Jump to content

Inputbox


FFREDIANELLI

Recommended Posts

This is the segment of the program that was adapted from inputbox to PROMPT,

This program in vcl accept a sql query with #[n/Ano:] in the place where it asks for the parameter

for example:

Select * from sometable where year(data)=#[n/Year:] and month(data)=#[n/Month:]

in vcl it stops ask first for the year and in another ask the month

 

Procedure TMainForm.UniSFBitBtn1Click(Sender: TObject);
var
  s, s1: string;
  i: Integer;
  c: string;
  k, tipo, pergunta: string;
  P1, p2, p3: Integer;
  iValue, iCode: Integer;
begin
  pGrid.Visible := false;
  Pquery.Visible := false;
  pResult.Align := alclient;
  pResult.Visible := true;
  if ((POS('UPDATE', strupper(qQueryQUERY.value)) > 0) OR
    (POS('DELETE', strupper(qQueryQUERY.value)) > 0) OR
    (POS('INSERT', strupper(qQueryQUERY.value)) > 0) OR
    (POS('EXEC', strupper(qQueryQUERY.value)) > 0)) AND (usunivel < 11) then
  BEGIN
    showmessage('Seu nível de acesso não permite executar esta alteração');
    exit
  END;
  qResult.SQL.Add(qQueryQUERY.value);

  s := qResult.SQL.Text;
  ref := '';
  while POS('#', s) > 0 do
  begin
    P1 := POS('#', s);
    p2 := POS(']', s);
    k := copy(s, P1, p2 - P1 + 1);
    tipo := copy(k, 3, 1);
    if tipo = 'n' then
    begin
      repeat
        Prompt(copy(k, 5, len(k) - 5), '', mtInformation, mbOKCancel,
          PromptCallBack);
        val(valor, iValue, iCode);
        if iCode <> 0 then
          valor := '';
      until valor <> '';
      strchange(s, k, valor);
      ref := ref + valor;
    end;
    if tipo = 's' then
    begin
      repeat

//---- In Debug it just pass here and do not stop...
        Prompt(copy(k, 5, len(k) - 5), '', mtInformation, mbOKCancel,
          PromptCallBack);
      until valor <> '';
      strchange(s, k, valor);
      ref := ref + valor;
    end;
  end;
  // sLabel1.Caption := 'Aguarde...';
  Application.ProcessMessages;
  qResult.SQL.Text := s;
  try
    if (POS('UPDATE', strupper(qResult.SQL.Text)) = 0) AND
      (POS('DELETE', strupper(qResult.SQL.Text)) = 0) AND
      (POS('EXEC ', strupper(qResult.SQL.Text)) = 0) THEN
    BEGIN
      qResult.open;
      for i := 0 to qResult.FieldCount - 1 do
      begin
        if qResult.Fields.DisplayWidth > 100 then
          qResult.Fields.DisplayWidth := 100;
      end;
    END
    ELSE
    BEGIN
      try
        qResult.Execute;
        showmessage('SQL executado');
      except
        showmessage('Erro ao executar comando');
      end;
    END;
  except
    showmessage('Erro ao interpretar query...');
  end;
end;

procedure TMainForm.PromptCallBack(Sender: TComponent; AResult: Integer;
AText: string);
begin
  if AResult = mrOK then
  begin
    valor := AText;
  end;
end;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...