Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Problem Redefining Field
Tue, Jan 3 2006 11:45 AMPermanent Link

"John Taylor"
Help Folks !!!

Using Delphi 5 and DBIsam 3.30

I'm trying to redefine a String field to a Memo field so as to increase the
capacity.  I'm doing the following with SQL

Adding a new temporary memo field  'SF_MEMO' - no problem
update the data in the temporary memo field 'SF_MEMO' from the string field
'SF_MSG' - no problem
drop the string field 'SF_MSG' - no problem
redefine the memo field 'SF_MEMO' to 'SF_MSG' - no problem.

Here's the problem, I have a Tdatamodule with a field SF_MSG define as
Tstring field.  I figured ,
no problem just drop the field definition from the Tdatamodule and use
Table.FieldByName('SF_MSG') whereever
it was needed.  BUT, I get runtime errors 'field does not exist' in db.pas
whenever this field is referenced with
FieldByName.  I can use dbsys and I see that the field SF_MSG does exist, is
a memo field. Does anyone
know what causes this ?  It is not a DBIsam exception but raised in db.pas

TIA

JT


Tue, Jan 3 2006 12:36 PMPermanent Link

Bernd Kuhlmann
John,
> Help Folks !!!
>
> Using Delphi 5 and DBIsam 3.30
>
> I'm trying to redefine a String field to a Memo field so as to increase
> the
> capacity.  I'm doing the following with SQL
>
> Adding a new temporary memo field  'SF_MEMO' - no problem
> update the data in the temporary memo field 'SF_MEMO' from the string
> field 'SF_MSG' - no problem
> drop the string field 'SF_MSG' - no problem
> redefine the memo field 'SF_MEMO' to 'SF_MSG' - no problem.
>
> Here's the problem, I have a Tdatamodule with a field SF_MSG define as
> Tstring field.  I figured ,
> no problem just drop the field definition from the Tdatamodule and use
> Table.FieldByName('SF_MSG') whereever
> it was needed.  BUT, I get runtime errors 'field does not exist' in db.pas
> whenever this field is referenced with
> FieldByName.  I can use dbsys and I see that the field SF_MSG does exist,
> is a memo field. Does anyone
> know what causes this ?  It is not a DBIsam exception but raised in db.pas

If you have added TFields to a table only those fields can be accessed by
FieldByName. All other fields can't be used even if they physically exist
in the table.
You can either add SF_MSG as a TMemoField or delete all other TFields.

Bernd

Tue, Jan 3 2006 12:49 PMPermanent Link

"John Taylor"
The underlying problem is that I already have field definitions in the Table
for all fields via
the fields editor.  Is there a way to at runtime redefine the field
definition from a string field
to a memo field ?  If I leave the field definition there as Tstringfield
then I get a
type mismatch runtime error after redefining the field.

JT
"Bernd Kuhlmann" <bernd.kuhlmann1@ewetel.net> wrote in message
news:5C6D15C9-24F2-46A7-9752-08624F86A518@news.elevatesoft.com...
> John,
>> Help Folks !!!
>>
>> Using Delphi 5 and DBIsam 3.30
>>
>> I'm trying to redefine a String field to a Memo field so as to increase
>> the
>> capacity.  I'm doing the following with SQL
>>
>> Adding a new temporary memo field  'SF_MEMO' - no problem
>> update the data in the temporary memo field 'SF_MEMO' from the string
>> field 'SF_MSG' - no problem
>> drop the string field 'SF_MSG' - no problem
>> redefine the memo field 'SF_MEMO' to 'SF_MSG' - no problem.
>>
>> Here's the problem, I have a Tdatamodule with a field SF_MSG define as
>> Tstring field.  I figured ,
>> no problem just drop the field definition from the Tdatamodule and use
>> Table.FieldByName('SF_MSG') whereever
>> it was needed.  BUT, I get runtime errors 'field does not exist' in
>> db.pas
>> whenever this field is referenced with
>> FieldByName.  I can use dbsys and I see that the field SF_MSG does exist,
>> is a memo field. Does anyone
>> know what causes this ?  It is not a DBIsam exception but raised in
>> db.pas
>
> If you have added TFields to a table only those fields can be accessed by
> FieldByName. All other fields can't be used even if they physically exist
> in the table.
> You can either add SF_MSG as a TMemoField or delete all other TFields.
>
> Bernd
>
>

Tue, Jan 3 2006 1:18 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

John


What's the problem with redefining the field in the IDE? If you're looking for a runtime solution it means a change to the app anyway. I don't know a way to redefine a field at runtime (doesn't mean there isn't one) but its a doddle to do in the IDE.

You do need to alter the definition not least because the way string fields and memo fields are treated is different.

Roy Lambert
Tue, Jan 3 2006 1:36 PMPermanent Link

Sean McCall
John,

If I understand your problem correctlt, you can redefine the
persistent fields at runtime as long as the table is closed:

ACursor: TDataset;
AIndex: Integer;
AFieldDef: TFieldDef;
AField: TField;

FreeAndNil(TheObsoletePersistentStringField);
ACursor.FieldDefs.Update;
AIndex := ACursor.FieldDefs.IndexOf('TheMemoFieldName');
if AIndex >= 0 then begin
  AFieldDef := ACursor.FieldDefs[AIndex];
  AField := AFieldDef.CreateField(ACursor);
  end {if field exists in table}
else begin
  raise Exception.Create('Could not find field in table');
end; {if field doesn't exist}


.... you could also just create a TMemoField directly with
TMemoField.Create and set all its properties. I use the
field definitions since I like to confirm that the field
exists in the table and also match the exact structure used
by the table.

Something to watch out for... you have a TStringField that
has to be removed which means that the variable that
references this field will be nil. If you always use
FieldByName, this won't be a problem.

Hope this helps,

Sean



> John
>
>
> What's the problem with redefining the field in the IDE? If you're looking for a runtime solution it means a change to the app anyway. I don't know a way to redefine a field at runtime (doesn't mean there isn't one) but its a doddle to do in the IDE.
>
> You do need to alter the definition not least because the way string fields and memo fields are treated is different.
>
> Roy Lambert
>
Tue, Jan 3 2006 1:38 PMPermanent Link

"John Taylor"
There was probably an easier way.  The persistent field definition was
(before redefining the table structure) TStringfield
The datamodule was being created first before the data tables were opened
and caused a type mismatch after the
structure was redefined.  I just deleted all the persistent field defs from
the datamodule and used fieldbyname to
access the data.

JT



"Roy Lambert" <roy.lambert@skynet.co.uk> wrote in message
news:15F12043-C8E6-4F7B-AE09-C58F35E08E54@news.elevatesoft.com...
> John
>
>
> What's the problem with redefining the field in the IDE? If you're looking
> for a runtime solution it means a change to the app anyway. I don't know a
> way to redefine a field at runtime (doesn't mean there isn't one) but its
> a doddle to do in the IDE.
>
> You do need to alter the definition not least because the way string
> fields and memo fields are treated is different.
>
> Roy Lambert
>

Image