I have a problem freeing a array of buttons i created on frmTransaction.Show I get an invalid operation error when the from shows again. And when I run the program with a different user it says there are items already with that name :) This code is the only part of my program where I free memory
SetLength(btnSale,iTrans);
for i := 1 to iTrans do
begin
readln(tPos,sPos);
iPos := Pos(';',sPos); //Gets positions of buttons
sTop := Copy(sPos,1,iPos-1);
sLeft := Copy(sPos,iPos+1,length(sPos));
btnSale[i] := TButton.Create(gbxSales);
with btnSale[i] do
begin
Parent := gbxSales;
name := 'Transaction' +
IntToStr(dmdata.tblTransactions['TransactionID']); //Creates buttons that represent Transactions
Caption := 'Sale ' + IntToStr(i);
Width := 153;
Height := 97;
Top := StrToInt(sTop);
left := strToInt(sleft);
show;
onClick := ClickSale;
end;
dmdata.tblTransactions.Next;
end;
procedure TfrmTransactions.FormHide(Sender: TObject);
var
i : integer;
begin
for i := low(btnSale) to high(btnSale) do //frees dynamically created objects
begin
btnSale[i].Free;
btnSale[i] := nil;
end;
end;