Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 9 of 9 total
Thread How To Question
Fri, Feb 17 2006 9:05 PMPermanent Link

Lance R
Question.  How would I / What is best way....    to insert / edit data when using a GUID?
In my example code below, obviously there is not an AsGUID for field type.

Thanks in advance!!

Lance

=================================================

type
   TAddress = class(TDBISAMTable)
   private
      FAddressID:   TGUID;
      FStreet: string;
      FCity: string;
      FState: string;
      FPostal: string;
      procedure SetAddressID(Value: TGUID);
      procedure SetStreet(Value: string);
      procedure SetCity(Value: string);
      procedure SetState(Value: string);
      procedure SetPostal(Value: string);

   public
      constructor Create(AOwner:TComponent); override;
      destructor Destroy; override;
      function Write: Boolean;

   end;


constructor TAddress.Create(AOwner: TComponent);
begin
   inherited;
   clear;
end;

destructor TAddress.Destroy;
begin

   inherited;
end

function TAddress.Write: Boolean;
begin
   self.SessionName:='MySession';
   self.Databasename:='MyDatabase';
   self.TableName:='Address';
   self.Exclusive:=FALSE;
   try
      self.Open;
                               self.Append;
      self.FieldByName('AddressID').AsGUID:=FAddressID; // Note sure about how to handle go between with GUID on App side and GUID on DBISAM side
      self.FieldByName('Street').AsString:=FStreet1;
      self.FieldByName('City').AsString:=FCity;
      self.FieldByName('State').AsString:=FState;
      self.FieldByName('Postal').AsString:=FPostal;
      self.Post;
   except
   end;


end;
Sat, Feb 18 2006 5:30 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Lance


If you're using V4 and you don't need to generate the GUID yourself then check out CURRENT_GUID as a default for the field.


Roy Lambert
Mon, Feb 20 2006 2:58 PMPermanent Link

"Lance R."
Roy,

I'm using latest build of V4.

So I assume, if I need to, say, have an address table and a person
table, I can insert the address into the Address table, using the
CURRENT_GUID, then grabbing that GUID from the Insert to use in the
Person table for the foreign key?

I think CURRENT_GUID will work.  But out of curiousity.. What is
necessary if I need to generate my own GUID?

Thanks for the assist!

Lance

Roy Lambert wrote:
> Lance
>
>
> If you're using V4 and you don't need to generate the GUID yourself then check out CURRENT_GUID as a default for the field.
>
>
> Roy Lambert
>
>
Mon, Feb 20 2006 3:09 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Lance


Quickly chopped from one of my apps

procedure TFmtEdForm.InsertImageExecute(Sender: TObject);
var
PicStream: TMemoryStream;
FileName: string;
_CID: string;
_guid: TGUID;
begin
if OpenPictureDialog1.Execute then begin
 FileName := LowerCase(OpenPictureDialog1.FileName);
 if not InLinePics.Locate('_Name', FileName, []) then begin
  PicStream := TMemoryStream.Create;
  PicStream.LoadFromFile(FileName);
  CreateGUID(_guid);
  _CID := GUIDtoString(_guid);
  InLinePics.Insert;
  InLinePics.FieldByName('_Name').AsString := ExtractFileName(FileName);
  InLinePics.FieldByName('_CID').AsString := _CID;
  TMemoField(InLinePics.FieldByName('_Item')).LoadFromStream(PicStream);
  InLinePics.Post;
  PicStream.Free;
 end else _CID := InLinePics.FieldByName('_CID').AsString;
 HTMLEdit.InsertHtml('<IMG src="cid:' + _CID + '" align=left>');
end;
end;


Roy Lambert
Mon, Feb 20 2006 3:31 PMPermanent Link

"Lance R."
Thank you Roy!

Dang.....   nothing like a quick response....  That worked great.

A second quick question and it might be part of your sample code.

I want to store an image for a person, like an avator or custom BMP or
other image format.  I have a field set as an ftGraphic type.

What would be the way to insert an image there.

Secondly...  Would it be better to create a secondary table with a
one-to-one relationship to keep all the images in one table (for speed)
and then use the lookup for the image when necessary for speed?

Thanks again Roy!

Lance


Roy Lambert wrote:
> Lance
>
>
> Quickly chopped from one of my apps
>
> procedure TFmtEdForm.InsertImageExecute(Sender: TObject);
> var
> PicStream: TMemoryStream;
> FileName: string;
> _CID: string;
> _guid: TGUID;
> begin
> if OpenPictureDialog1.Execute then begin
>   FileName := LowerCase(OpenPictureDialog1.FileName);
>   if not InLinePics.Locate('_Name', FileName, []) then begin
>    PicStream := TMemoryStream.Create;
>    PicStream.LoadFromFile(FileName);
>    CreateGUID(_guid);
>    _CID := GUIDtoString(_guid);
>    InLinePics.Insert;
>    InLinePics.FieldByName('_Name').AsString := ExtractFileName(FileName);
>    InLinePics.FieldByName('_CID').AsString := _CID;
>    TMemoField(InLinePics.FieldByName('_Item')).LoadFromStream(PicStream);
>    InLinePics.Post;
>    PicStream.Free;
>   end else _CID := InLinePics.FieldByName('_CID').AsString;
>   HTMLEdit.InsertHtml('<IMG src="cid:' + _CID + '" align=left>');
> end;
> end;
>
>
> Roy Lambert
>
>
Mon, Feb 20 2006 5:24 PMPermanent Link

Jeff Cook
"Lance R." <lance@lance.ws> wrote on Mon, 20 Feb 2006 12:28:14 -0800
>
>Secondly... Would it be better to create a secondary table with a
>one-to-one relationship to keep all the images in one table (for speed)
>and then use the lookup for the image when necessary for speed?
>
Lance



I think I can answer part 2 of your question

DBISAM only retrieves the BLOB fields when required, so you'd only be making extra work for yourself by having the images in a separate table.  So if you are (say) showing the table in a grid and scrolling back and forth, the BLOB's don't get retrieved.

There might be other reasons to do this, but speed probably isn't one of them.

Cheers


Jeff

P.S.  You might have to wait for Roy to wake up in the morning for part 1.  J.



--
Jeff Cook
Aspect Systems Ltd
Phone: +64-9-424 5388
Skype: jeffcooknz
www.aspect.co.nz



Mon, Feb 20 2006 5:42 PMPermanent Link

"Lance R."
Jeff,

that makes sense if DBISAM ignores the blob fields.

I appreciate the insight.

Lance

Jeff Cook wrote:
> "Lance R." <lance@lance.ws> wrote on Mon, 20 Feb 2006 12:28:14 -0800
>> Secondly... Would it be better to create a secondary table with a
>> one-to-one relationship to keep all the images in one table (for speed)
>> and then use the lookup for the image when necessary for speed?
>>
> Lance
>
>
>
> I think I can answer part 2 of your question
>
> DBISAM only retrieves the BLOB fields when required, so you'd only be making extra work for yourself by having the images in a separate table.  So if you are (say) showing the table in a grid and scrolling back and forth, the BLOB's don't get retrieved.
>
> There might be other reasons to do this, but speed probably isn't one of them.
>
> Cheers
>
>
> Jeff
>
> P.S.  You might have to wait for Roy to wake up in the morning for part 1.  J.
>
>
>
> --
> Jeff Cook
> Aspect Systems Ltd
> Phone: +64-9-424 5388
> Skype: jeffcooknz
> www.aspect.co.nz
>  
>
>
>
>
Tue, Feb 21 2006 2:48 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Lance


First I tend to use ftMemo fields rather than ftBlob or ftGraphic - at the database level they're the same and you can access ftMemos via .AsString.

Storing it with OP is a doddle - get the image into a stream and stuff the stream into the field. I tend to use TMemoryStream and memofield.LoadFromStream eg

     TMemoField(MailImages.FieldByName('_Item')).LoadFromStream(imgLoad);

But if you load the image into a TStringList you can stuff it in via .AsString := .Text


Roy Lambert
Tue, Feb 21 2006 2:35 PMPermanent Link

"Lance R."
Roy,

thats an interesting concept.  I like.

Thanks for the assists!!

Lance
Roy Lambert wrote:
> Lance
>
>
> First I tend to use ftMemo fields rather than ftBlob or ftGraphic - at the database level they're the same and you can access ftMemos via .AsString.
>
> Storing it with OP is a doddle - get the image into a stream and stuff the stream into the field. I tend to use TMemoryStream and memofield.LoadFromStream eg
>
>       TMemoField(MailImages.FieldByName('_Item')).LoadFromStream(imgLoad);
>
> But if you load the image into a TStringList you can stuff it in via .AsString := .Text
>
>
> Roy Lambert
>
>
Image