Recent

Author Topic: Free TField in db  (Read 2356 times)

cappe

  • Full Member
  • ***
  • Posts: 191
Free TField in db
« on: October 26, 2018, 10:48:20 am »
I have a project as an example:

  TForm1 = class(TForm)
    Button1: TButton;
    DBConnection: TZConnection;
    ZQuery1: TZQuery;
    ZQuery1BAC1: TStringField;
    ZQuery1BAC2: TLongintField;
    ZQuery1BAC3: TStringField;
    ZQuery1BAC4: TStringField;
    ZQuery1BAC5: TDateTimeField;
    ZQuery1BAC6: TStringField;
    ZQuery1BAC7: TStringField;
    ZQuery1ID: TStringField;
    procedure Button1Click(Sender: TObject);
  private

  public

  end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ZQuery1.Fields[1].Free;        <-- Is correct?
end;         


The question is if "ZQuery1.Fields[1].Free" is correct to free the tfield numer 1?
« Last Edit: October 26, 2018, 10:58:53 am by cappe »

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Free TField in db
« Reply #1 on: October 26, 2018, 11:11:47 am »
You shouldn't have to manually free any of the fields shown here.  The ones you created in the designer will be automatically free'd when you close the form (the form is their parent)
The list of fields held by ZQuery are automatically created when you call zquery.open, and automatically free'd when you call zquery.close.

What is it you are trying to achieve?
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

cappe

  • Full Member
  • ***
  • Posts: 191
Re: Free TField in db
« Reply #2 on: October 26, 2018, 11:23:07 am »
I have to find the correct way to free only a TField from code. I need to do this

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Free TField in db
« Reply #3 on: October 26, 2018, 01:58:26 pm »
 :( removing a field from an existing SQL database can only be done by a SQL  query. Although it is possible to do that using e.g. tiOPF. Which abstracts away that query to Pascal code.
Usually it is better to NOT remove the field, but write a new query that omits the field.
It requires a database restructure to actually remove it. Which is I think what you mean.
« Last Edit: October 26, 2018, 02:02:23 pm by Thaddy »
Specialize a type, not a var.

cappe

  • Full Member
  • ***
  • Posts: 191
Re: Free TField in db
« Reply #4 on: October 26, 2018, 04:05:03 pm »
In fact it would seem to be true, once canceled it works, but in the subsequent operations it gives me some problems. Unless someone knows how to do it.

 

TinyPortal © 2005-2018