Board index » delphi » TField dynamic

TField dynamic

I would like to extend the data base at run-time of the program over SQL.
Around the fields to process to be able I produce components dynamically.

If RequestLive of the query is set on false, also all this functions
marvelously, only with a updatable query has I the problem that I when
opening the data base an error message receives that the
field " userfield " can not be found. Which false I make or as can I the
problem go around. Are grateful for each tip! BDE and Interbase data base
are used.

Var
sql:string;
s:Tstringfield;
 begin

  sql:='alter table adress add USERFIELD VARCHAR(5)';
  query1.SQL.Clear;
  query1.SQL.Add(sql);
  query1.ExecSQL;
  Name:='USERFELD';

  Adressquery.close;
  s:=Tstringfield.Create(self);
  s.FieldName:=name;
  s.FieldKind:=fkData;
  s.Name:=Adressquery.Name+name;
  s.readonly:=false;
  s.Index:=Adressquery.FieldCount;
  s.DataSet:=Adressquery;
  Adressquery.FieldDefs.Add(Adressquery.Name+name,ftstring,30,false);
  Adressquery.FieldDefs.Update;

  //At this line come the error
  Adressquery.open;

end;

Sorry for my english!

Gerhard ecl.gmbh@t online.de

 

Re:TField dynamic


Just a {*word*218} here, but you do realize that your variable that stores the
name is getting set to UserFeld not UserField.

--
Glenn Hancock
SofTek Software Int'l Inc.
www.softeksoftware.com
ghanc...@softeksoftware.com
770-490-7899

Re:TField dynamic


Sorry, this was a little mistake in this example. But the error is real.

Gerhard

Quote
> Just a {*word*218} here, but you do realize that your variable that stores the
> name is getting set to UserFeld not UserField.

> --
> Glenn Hancock
> SofTek Software Int'l Inc.
> www.softeksoftware.com
> ghanc...@softeksoftware.com
> 770-490-7899

Re:TField dynamic


Quote
>If RequestLive of the query is set on false, also all this functions
>marvelously

That is strange.  Your code should not work

Try this

 Adressquery.FieldDefs.Update  ;
  for i := 0 to Adressquery.FieldDefs.Count - 1 do
   //create persistent field that do not exist
   if Adressquery.FindField(Adressquery.FieldDefs[i].Name) = nil then
      Adressquery.FieldDefs.Items[i].CreateField(Adressquery);

  //At this line come the error
  Adressquery.open;
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:TField dynamic


The same error! The Function Getfieldnames find the Field. But when i open
the query
the error say that the field can not be found!

Gerhard

"Brian Bushay TeamB" <BBus...@Nmpls.com> schrieb im Newsbeitrag
news:tfv3mtoiml8pqe57vsboi3an4r7dlv3hft@4ax.com...

Quote

> >If RequestLive of the query is set on false, also all this functions
> >marvelously
> That is strange.  Your code should not work

> Try this

>  Adressquery.FieldDefs.Update  ;
>   for i := 0 to Adressquery.FieldDefs.Count - 1 do
>    //create persistent field that do not exist
>    if Adressquery.FindField(Adressquery.FieldDefs[i].Name) = nil then
>       Adressquery.FieldDefs.Items[i].CreateField(Adressquery);

>   //At this line come the error
>   Adressquery.open;
> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:TField dynamic


The same error! The Function Getfieldnames find the Field. But when i open
the query the error say that the field can not be found!

Gerhard

"Brian Bushay TeamB" <BBus...@Nmpls.com> schrieb im Newsbeitrag
news:tfv3mtoiml8pqe57vsboi3an4r7dlv3hft@4ax.com...

Quote

> >If RequestLive of the query is set on false, also all this functions
> >marvelously
> That is strange.  Your code should not work

> Try this

>  Adressquery.FieldDefs.Update  ;
>   for i := 0 to Adressquery.FieldDefs.Count - 1 do
>    //create persistent field that do not exist
>    if Adressquery.FindField(Adressquery.FieldDefs[i].Name) = nil then
>       Adressquery.FieldDefs.Items[i].CreateField(Adressquery);

>   //At this line come the error
>   Adressquery.open;
> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:TField dynamic


Quote
>The same error! The Function Getfieldnames find the Field. But when i open
>the query
>the error say that the field can not be found!

I can't reproduce your problem using Paradox tables.  What dattabase are you
using?  Have you defined persistent Tfields?

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:TField dynamic


I use Interbase with BDE. But i have found the error. I must disconnect from
Database
and the i can connect without a error. Thank you for your help.

"Brian Bushay TeamB" <BBus...@Nmpls.com> schrieb im Newsbeitrag
news:djl6mt4p3h8ia3s1uu6n6vi68i7181hvhm@4ax.com...

Quote
> >The same error! The Function Getfieldnames find the Field. But when i
open
> >the query
> >the error say that the field can not be found!

> I can't reproduce your problem using Paradox tables.  What dattabase are
you
> using?  Have you defined persistent Tfields?

> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Other Threads