I am trying to create a while loop that will allow me to change to the name of a button within the loop (see code). I simply want to load the name from the table onto the caption, but don't want to have all these lines in code and want to make a function or procedure call. There is 64 buttons (I just did 16 for viewing. No matter what I do I can't seem to modify the frmSales.Pump1 portion of it.
I would like something like
frmSales.Pump + (variable).caption = frmSales.tblFuel_.Lookup('PumpNumber', (varriable), 'PumpName');
Any help would be greatly appreciated.
Procedure PumpNames; //Loads up on form creation
begin
frmSales.Pump1.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '01', 'PumpName');
frmSales.Pump2.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '02', 'PumpName');
frmSales.Pump3.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '03', 'PumpName');
frmSales.Pump4.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '04', 'PumpName');
frmSales.Pump5.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '05', 'PumpName');
frmSales.Pump6.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '06', 'PumpName');
frmSales.Pump7.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '07', 'PumpName');
frmSales.Pump8.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '08', 'PumpName');
frmSales.Pump9.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '09', 'PumpName');
frmSales.Pump10.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '10', 'PumpName');
frmSales.Pump11.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '11', 'PumpName');
frmSales.Pump12.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '12', 'PumpName');
frmSales.Pump13.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '13', 'PumpName');
frmSales.Pump14.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '14', 'PumpName');
frmSales.Pump15.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '15', 'PumpName');
frmSales.Pump16.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '16', 'PumpName');
end;
Vote for best question.
Score: 0
# Vote: 0
Date Posted: 1-Jul-2014, at 9:25 AM EST
From: Al Herman
Re: Trying to create a while loop to encompass component nam
> {quote:title=Al Herman wrote:}{quote}
> I am trying to create a while loop that will allow me to change to the name of a button within the loop (see code). I simply want to load the name from the table onto the caption, but don't want to have all these lines in code and want to make a function or procedure call. There is 64 buttons (I just did 16 for viewing. No matter what I do I can't seem to modify the frmSales.Pump1 portion of it.
>
> I would like something like
> frmSales.Pump + (variable).caption = frmSales.tblFuel_.Lookup('PumpNumber', (varriable), 'PumpName');
>
> Any help would be greatly appreciated.
>
> Procedure PumpNames; //Loads up on form creation
> begin
> frmSales.Pump1.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '01', 'PumpName');
> frmSales.Pump2.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '02', 'PumpName');
> frmSales.Pump3.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '03', 'PumpName');
> frmSales.Pump4.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '04', 'PumpName');
> frmSales.Pump5.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '05', 'PumpName');
> frmSales.Pump6.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '06', 'PumpName');
> frmSales.Pump7.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '07', 'PumpName');
> frmSales.Pump8.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '08', 'PumpName');
> frmSales.Pump9.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '09', 'PumpName');
> frmSales.Pump10.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '10', 'PumpName');
> frmSales.Pump11.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '11', 'PumpName');
> frmSales.Pump12.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '12', 'PumpName');
> frmSales.Pump13.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '13', 'PumpName');
> frmSales.Pump14.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '14', 'PumpName');
> frmSales.Pump15.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '15', 'PumpName');
> frmSales.Pump16.Caption := frmSales.tblFuel_.Lookup('PumpNumber', '16', 'PumpName');
> end;