Nesler, Thomas J wrote:
> I am writing a general purpose Export/Import utility and I need to
> handle memo fields differently when I am copying data from one table to
> another.
>
> I tried doing this:
>
> Try
> Stream1 := TBlobStream.Create(Table1.Fields[X], bmRead);
> Stream2 := TBlobStream.Create(Table2.Fields[X], bmRead);
> Stream2.CopyFrom(Stream1, Stream1.Size);
> except
> Showmessage('Unable to Copy Memo field');
> ErrorCode := True;
> end;
>
> But I got this syntax error message: [Error] Export.pas(114):
> Incompatible types: 'TBlobField' and 'TField'
Right. TBlobStream's constructor expects an argument with *compile-time*
type of TBlobField. TTable's Fields property only has compile-time type
TField, even some of its values might have the *run-time* type of
TBlobField.
It's not a syntax error. It's a type-checking error.
> The "X" variable denotes the position of the field in the field
> structure. What do I call the field in my code?
>
> I have already trapped for the fields that are memo fields in my
> procedure.
If you have something with compile-time type TFoo and run-time type
TBar, then you can use a type-cast to tell the compiler to treat it as
though it has compile-time type TBar instead.
If you're sure the value has type TBar, then use a function-style type-cast:
TBlobStream.Create(TBlobField(Table1.Fields[x]), bmRead)
If you would like the program to confirm at run time that the value has
the intended type, then use a checked type-cast:
TBlobStream.Create(Table1.Fields[x] as TBlobField, bmRead)
I recommend the latter.
I also recommend giving your variables better names, such as SourceTable
and DestTable, so nobody needs to remember whether 1 or 2 is the thing
you're copying.
--
Rob