Recent

Author Topic: RX-Lib Field creation by program.  (Read 2590 times)

iru

  • Sr. Member
  • ****
  • Posts: 321
RX-Lib Field creation by program.
« on: May 19, 2017, 03:19:39 am »
Gentlefolk,

Environment: Linux Mint 18.1,laz 1.6,FPC 3.0.0. RX from lazarus-ccr-svn-5845-components-rx-trunk.zip.

Does anyone have an example of creating fields by program?

I have the following code which crashes on the 'open' with an unknown field type.

  vField := tField.Create(Self);
  vField.DisplayLabel := 'fredo';
  vField.FieldName := 'laced';
  vField.SetFieldType(ftString);
  RX1.Fields.Add(vField);

  RX1.Open; 

The 'open' code (procedure TField.SetFieldType(AValue: TFieldType);) in Fields.inc is 'empty',no code at all.   

Any help appreciated,Ian.               


ttomas

  • Full Member
  • ***
  • Posts: 245
Re: RX-Lib Field creation by program.
« Reply #1 on: May 19, 2017, 11:54:22 am »
Never create TField. In your case you need TStringField descendat
Code: Pascal  [Select][+][-]
  1. vField := TStringField.Create(Self);
  2. ...
  3. // vField.SetFieldType(ftString);  
  4.  

iru

  • Sr. Member
  • ****
  • Posts: 321
Re: RX-Lib Field creation by program.
« Reply #2 on: May 19, 2017, 02:09:57 pm »
hank you ttomas,

That helps  my code and understanding of things, however.....
The 'open' works.

The following code fails with 'No dataset assigned for field: place'
  RX1.Open;
  RX1.First;
  RX1.Edit;
  RX1.FieldByName('place').AsString := '10'; 

There is a complete (I Think) structure:

DBGrid1>DataSource1>RX1.I thought the 'place' field would be relatedto RX1.

If I add  ' vField.DataSet := RX1'   as follows

  vField.DataSet := RX1;
  RX1.Fields.Add(vField); 

Compiles clean but gives 'Duplicate fieldname: 'place' on RX1.Fields.Add

I am lost...Any help (examples?) appreciated, Ian.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: RX-Lib Field creation by program.
« Reply #3 on: May 20, 2017, 10:39:19 am »
How about the oldfasioned way? This is an example for building a memtable with tbufdataset:
Code: Pascal  [Select][+][-]
  1. begin
  2.   ClDataSet := TBufDataset.Create(nil);
  3.   with ClDataSet do
  4.   begin
  5.     FieldDefs.Add('veldnaam',ftString, 50);
  6.     FieldDefs.Add('waarde',ftString, 255);
  7.   end;
  8.   ClDataset.CreateDataset;
  9.   ClDataSet.Active := true;
  10. end;                                
  11.  
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: RX-Lib Field creation by program.
« Reply #4 on: May 20, 2017, 10:02:04 pm »
Setting DataSet property of Field also adds Field in Fields of Dataset.
Check SetDataSet method of TField!

vField.DataSet := RX1;
//  RX1.Fields.Add(vField); //Field is added in prev line

 

TinyPortal © 2005-2018