0
In jQuery we can make reference to an element of the form below:
var tipo = "B";
$("#campoTipo"+tipo).val("Teste");
which would be the same as:
$("#campoTipoB").val("Teste");
I need in Delphi, disable some buttons that depend on a Query
procedure TFormCupom.BitBtn3Click(Sender: TObject);
var
ponteiro: Integer;
painel: TPanel;
begin
DM.FDConexao.Connected := true;
ponteiro := 0;
with DM.FDQ_Recentes do
begin
close;
sql.clear;
sql.add('SELECT * FROM rotativo');
open;
First; // primeiro
while not eof do
begin
inc(ponteiro);
painel := FindComponent('Pn' + IntToStr(ponteiro)) as TPanel;
if painel <> nil then
painel.Visible := false;
Next; // proximo
end;
end;
end;
I couldn’t understand why I asked the database. The code does not use any query data. To know why the code is not working you need to know how the Tpanel were created and named. Findcomponent will return the reference to the Panel only if it is the Owner of the Panel, and if Panel.Name is correctly specified.
– Ricardo Alves Carvalho
Ricardo, Panel are created at design time and are invisible. According to the query they will be visible or not.
– Ezequiel Tavares
Has each Tpanel been named in the Object Inspector (Pn1, Pn2, ...)? How many Panels are in the form?
– Ricardo Alves Carvalho
Yes. In Object Inspector. There are several but the ones I need to handle are 7. Pn1... Pn7
– Ezequiel Tavares
Ok. And what you read from the query to determine which panel will be enabled?
– Ricardo Alves Carvalho
Actually each loop will activate the corresponding Panel. Ex. var pointer = 1 Pn1 is visible. I will use the data from the fields for popular Label’s that have inside the Panel.
– Ezequiel Tavares
Let’s go continue this discussion in chat.
– Ricardo Alves Carvalho
I tried to chat, but I couldn’t. I did a test like this and it worked:Project Tform2.Button1click(Sender: Tobject); var panel: Tpanel; pointer: integer; Begin for pointer := 1 to 5 of Begin panel := Findcomponent('Pn' + Inttostr(pointer)) as Tpanel; if Assigned() then panel.Visible := True; end; end;
– Ricardo Alves Carvalho
As soon as I get home I’ll test it and come back here
– Ezequiel Tavares