Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9202863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:20:57+00:00 2026-06-17T23:20:57+00:00

Currently when i click on a button it will create some shapes on a

  • 0

Currently when i click on a button it will create some shapes on a new form. Once i close the new form how can i destroy the shapes it made.

I can add more info if needed but was hopeing there was a simple way to destroy all TMachine instances when the form closed.

TMachine is a TShape Class

procedure TFLayout1.GetClick(Sender: TObject);
var
  azone: string;
  adept: string;
  machine : TMachine;
begin
  fdb.count := 0;  //keeps track of number of machines in zone
  azone := MyDataModule.fDB.GetZone(Name);    //gets name of zone
  adept := TButton(Sender).Name;       //gets name of dept
  fdeptlayout.ListBox1.Clear;

  fdeptlayout.show;
  with fdeptlayout.ADOQuery1 do
    begin
         sql.Clear;
         sql.BeginUpdate;
         sql.Add('SELECT');
         sql.Add(' *');
         sql.Add('FROM');
         sql.Add(' `MList`');
         sql.Add('WHERE `Zone` = :myzone ');
         sql.Add(' AND `Dept` = :mydept');
         sql.EndUpdate;

         parameters.ParamByName('myzone').Value := azone;
         parameters.ParamByName('mydept').Value := adept;
         open;
    end;

  //gets number of machines in total
  while not fdeptlayout.ADOQuery1.Eof do
    begin
      fdb.count := fdb.count+1;
      fdeptlayout.ADOQuery1.Next;
    end;

  //restarts back at first query
  fdeptlayout.ADOQuery1.First;

   //clears the last x value
   fdb.LastX :=0;

  //creates the shape
  while not fdeptlayout.ADOQuery1.Eof do
    begin
        machine := MachineShape.TMachine.Create(self);
        machine.Parent := fdeptlayout;
        machine.PlaceShape(44,44,'CM402','first','123/33/123');
        fdeptlayout.ListBox1.Items.Add(fdeptlayout.ADOQuery1.FieldByName('Name').AsString);
        fdeptlayout.ADOQuery1.Next;
    end;
end;

TMachine Class

unit MachineShape;


interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, extctrls,myDataModule,Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type

TMachine = class(TShape)
  private
    { Private declarations }
  public
    { Public declarations }
    procedure PlaceShape(sizeW,sizeH :integer; name, order,asset : string);
  end;
implementation



    Procedure TMachine.PlaceShape(sizeW,sizeH :integer; name, order,asset : string);
    begin
       self.width :=  sizeW;
       self.height := sizeH;
       self.top := 136;
       self.left := MyDataModule.fDB.LastX +2;//set left
       MyDataModule.fDB.lastx := left + sizeW;
       showmessage(inttostr(mydatamodule.fDB.LastX));
    end;

end.

FDeptLayout

unit DeptLayout;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls,mydatamodule, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB, Vcl.StdCtrls,
  Vcl.ExtCtrls;

type
  TfDeptLayout = class(TForm)
    ADOQuery1: TADOQuery;
    ListBox1: TListBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fDeptLayout: TfDeptLayout;

implementation

{$R *.dfm}

procedure TfDeptLayout.FormClose(Sender: TObject; var Action: TCloseAction);
begin

end;

end.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:20:58+00:00Added an answer on June 17, 2026 at 11:20 pm

    The shown code is taking advantage of the VCL ownership model and the form will free it for you, as you just pass the form itself as the owner of your components when you create it:

    machine := MachineShape.TMachine.Create(self);
    

    as this is called from the TFLayout1 class, when the particular instance of the form is destroying itself, it will free all the owned components.

    For a little more info, you can read the article: Owner vs. Parent in Delphi.

    Edit

    From comments, it resulted you create the TMachine instances on a class different of the form on which you show it, and you don’t destroy the form instance when you close it, so, you can reach what you want making this changes:

    • Make the form in which the shapes are shown the owner, changing your code to create them to this:

      //don't use self, now the parent is the instance referenced by fdeptlayout
      machine := MachineShape.TMachine.Create(fdeptlayout);
      
    • On your Tfdeptlayout class, add a OnClose handler with this code:

      begin
        for I := ComponentCount - 1 downto 0 do
          if Components[I] is TMachine then
            Components[I].Free;
      end;
      

    That said, you really have to read the documentation and referenced articles to gain some understanding of what’s going on behind the scenes in your Delphi application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a simple form that when you click the save button will
Goal: Once i click on the start button on my user interface, i currently
I currently have a delayed task that runs whenever I click a button. Clicking
I currently have this: function submit() { document.getElementById(lostpasswordform).click(); // Simulates button click document.lostpasswordform.submit(); //
I want to add a UIViewController on my current UIView on a button click
I have a button that will programmatically create a UIImageView with an image for
Current requirement is on button click I am getting a json data through ajax
THis is what i currently have click = false; if click $(el).on('click', 'li', {})
Currently i have this: $(.splitCol).click(function () { $.cookie('whichColumn', 'split'); $(.threeCol .active).removeClass(active); $(.leftCol .active).removeClass(active); $(.splitCol
I've got a button for which I dynamically create target URI with jquery. Controller

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.