How To…Launch the DADE Query Designer in Code

Question

“How do I launch the Query Designer outside the designer as a stand-alone dialog?”

Solution

The query designer can be launched separate from the designer and used to generate SQL as a stand-alone dialog. Start by creating a TdaQueryDesignerForm object and assigning it a SQL object to use. Once the dialog has been used and closed, access the SQL object to obtain the generated SQL code.

Download: LaunchQueryDesignerViaCode.zipLaunchQueryDesignerViaCodeADO.zip

Delphi code sample:

procedure TForm1.Button1Click(Sender: TObject);
var
  lDialog: TdaQueryDesignerForm;
begin
  lDialog := TdaQueryDesignerForm.Create(Application);

  lDialog.SQLClass := TdaSQL;
  lDialog.SQL.Assign(FSQL);

  lDialog.Initialize;


  {show form}
  if (lDialog.ShowModal = mrOK) then
    begin
      FSQL.Assign(lDialog.SQL);

      Memo1.Lines.AddStrings(lDialog.SQL.SQLText);
    end;

  lDialog.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin

  FSession := TdaBDESession.Create(Self);

  {set SQL properties}
  FSQL := TdaSQL.Create(Self);

  FSQL.Session := FSession;

  FSQL.AllowSelfJoin := True;
  FSQL.DatabaseName := 'DBDEMOS';
  FSQL.DatabaseType := dtParadox;
  FSQL.SQLType := sqBDELocal;
end;