BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Adding Field Defs at runtime

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Multi-Tier)
View previous topic :: View next topic  
Author Message
FDWeller
Guest





PostPosted: Fri Jul 04, 2003 5:47 pm    Post subject: Adding Field Defs at runtime Reply with quote



I'm trying to build a ClientDataset at run time using pure code. The
AddFieldDefs works fine for everything except the field necessary to support
a nested dataset (I have a master/detail relationship between the two and
want to explore nesting the datasets as that should allow me to save only
one file to disk). When I try to add the field, I get an "Invalid Field
Type" error message when I call "CreateDataset".
Any ideas?

Current code sets field type to ftDataSet and adds faLink to the Attributes.
Size is 0.

--Fred


Back to top
Manuel Parma
Guest





PostPosted: Sat Jul 05, 2003 11:25 pm    Post subject: Re: Adding Field Defs at runtime Reply with quote



I send you an example with unit and form in text format
Manuel
Form:
==============================
object Form1: TForm1
Left = 178
Top = 120
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 16
Top = 12
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object DBGrid1: TDBGrid
Left = 8
Top = 44
Width = 521
Height = 293
DataSource = DataSource1
TabOrder = 1
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object ClientDataSet1: TClientDataSet
Aggregates = <>
Params = <>
Left = 124
Top = 12
end
object DataSource1: TDataSource
DataSet = ClientDataSet1
Left = 168
Top = 12
end
end
===============================

Unit:
===============================
unit Unit25;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBClient, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure GetStruct(Target: TFieldDefs);
procedure AddChildDefs(Source: TFieldDef; sName: string; oDataType:
TFieldType;
iLen: integer);
begin
with Source.AddChild do
begin
Name := sName;
DataType := oDataType;
Size := iLen;
end;
end;
var
oFieldDef, oPersFieldDef: TFieldDef;
begin
Target.Clear;

Target.Add('QueryNumber', ftInteger);
Target.Add('Description', ftString, 60);
Target.Add('DisplayName', ftString, 60);
Target.Add('DisplayRows', ftInteger);
Target.Add('Flags', ftstring, 20);
Target.Add('XSL', ftMemo);
Target.Add('ExtraInfo', ftMemo);

oFieldDef := Target.AddFieldDef;
with oFieldDef do
begin
Name := 'Attributes';
DataType := ftDataSet;
end;

AddChildDefs(oFieldDef, 'AttName', ftString, 40);
AddChildDefs(oFieldDef, 'AttDescription', ftString, 80);

oFieldDef := oFieldDef.AddChild;
with oFieldDef do
begin
Name := 'AttLkpValues';
DataType := ftDataSet;
end;

AddChildDefs(oFieldDef, 'LkpCode', ftString, 40);
AddChildDefs(oFieldDef, 'LkpKind', ftInteger, 0);

oFieldDef := Target.AddFieldDef;
with oFieldDef do
begin
Name := 'DefaultParameters';
DataType := ftDataSet;
end;

AddChildDefs(oFieldDef, 'Name', ftString, 40);
AddChildDefs(oFieldDef, 'DataType', ftInteger, 0);

oFieldDef := oFieldDef.AddChild;
with oFieldDef do
begin
Name := 'PrmLkpValues';
DataType := ftDataSet;
end;

AddChildDefs(oFieldDef, 'LkpCode', ftString, 40);
AddChildDefs(oFieldDef, 'LkpKind', ftInteger, 0);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
GetStruct(ClientDataSet1.FieldDefs);
ClientDataSet1.CreateDataSet;
end;




end.
===============================


Back to top
FDWeller
Guest





PostPosted: Thu Jul 10, 2003 7:16 am    Post subject: Re: Adding Field Defs at runtime Reply with quote



Thanks! Looks like there isn't anything special going on here, I'll have to
figure out where my error is coming from.

--FDWeller


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Multi-Tier) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.