Create delphi pas file with constants for commands and command parameters from daschema

Is there a way to generate a .pas file with constants for the commands and command parameters from a daschema (similar to what happens for the tables and table fields.

I see this data is missing in the DASchemaClient_Intf file
It would be useful to be able to execute the commands from the client.
An even better solution would be if code was generated that executes the command

My daschema is hosted in a .NET RO server.
My client is delphi code

Hi,

Can you give an example of such generated file, pls?

Yes, I use a tool i made based on your suggestion
generatestronglytypeddelphi.exe --daschema=genericdb.daSchema --dstpath=…..\daschemastronglytyped

This outputs the attached file

Code:

function generateSources(const srcdaschema,dstpath:string):boolean;
var
  aSchema: TDAClientSchema;
  lf: TClientUnitSchemaGenerator;
  ls: TServerUnitSchemaGenerator;
  clienttargetfilename, servertargetfilename: string;
begin
  try
    aSchema := TDAClientSchema.Create(nil);
    try
      aSchema.LoadFromFile(srcdaschema);
      aSchema.Name :=ChangeFileExt(ExtractFileName(srcdaschema), '');

      clienttargetfilename := IncludeTrailingPathDelimiter(dstpath)+aSchema.Name+'DASchemaClient_Intf.pas';
      servertargetfilename := IncludeTrailingPathDelimiter(dstpath)+aSchema.Name+'DASchemaServer_Intf.pas';
      lf := TClientUnitSchemaGenerator.Create(aSchema);
      try
        lf.WriteCode(clienttargetfilename);
      finally
        lf.Free;
      end;

      ls := TServerUnitSchemaGenerator.Create(aSchema);
      try
        ls.ClientUnitName := ChangeFileExt(ExtractFileName(clienttargetfilename), '');

        ls.WriteCode(servertargetfilename);
      finally
        ls.Free;
      end;
    finally
      aSchema.Free;
    end;
    Writeln('Generated file '+servertargetfilename);
    Writeln('Generated file '+clienttargetfilename);
    Result:=True;
  except
    on E: Exception do
    begin
      Writeln(E.ClassName, ': ', E.Message);
      Result:=False;
    end;
  end;
end;

GenericDBDASchemaClient_Intf.pas (663.6 KB)

Hi,

executing commands is very simple:

    function Execute(aCommandName: string): Integer; overload;
    function Execute(aCommandName: string; aInputParameters: DataParameterArray): Integer; overload;
    function Execute(aCommandName: string; aInputParameters: DataParameterArray; out aOutputParameters: DataParameterArray): Integer; overload;
    function Execute(aCommandName: string; aParamNames: array of string; aParamValues: array of Variant): Integer; overload;
    function Execute(aCommandName: string; aParamValues: array of Variant): Integer; overload;

I don’t think that it needs strongly-typed file for commands.

simple examples:

DARemoteCommand.Execute('mycommand');
DARemoteCommand.Execute('mycommand1', [p1, p2, p3]);
DARemoteCommand.Execute('mycommand2', [name], [value]);

if you are using output parameters, you should use

function Execute(aCommandName: string; aInputParameters: DataParameterArray; out aOutputParameters: DataParameterArray): Integer; 

Hello Evgeny,
I am using the bottom format with output parameters.
My question is a bit different:
I don’t like using string literals ‘mycommand1’.
I prefer using constant identifiers generated by a RO tool (similar to nme_XXX for DA schema names)
Is that possible.

The code to call a command is indeed simple, I was only hinting that RO could generate these simple functions (with all the input and output parameters and an extra TRORemoteService parameter)

FYI: My calling code below

procedure addDataParameter(dpa:DataParameterArray;const name:string;value:variant);
var
  dp:DataParameter;
begin
  dp:=dpa.Add();
  dp.Name:=name;
  dp.Value:=value;
end;
function TdmGenericDBService.updatePrijsTabel(prt_primkey:integer;price:currency;quality:integer;const origine:string;origine_primkey:integer):integer;
var
  dpaIn:DataParameterArray;
  dpaOut:DataParameterArray;
  RemoteCommand:TDARemoteCommand;
begin
  RemoteCommand:=nil;
  dpaOut := nil;
  dpaIn := DataParameterArray.Create();
  try
    addDataParameter(dpaIn,prm_prt_primkey,prt_primkey);
    addDataParameter(dpaIn,prm_prt_prijs,price);
    addDataParameter(dpaIn,prm_prt_quality,quality);
    addDataParameter(dpaIn,prm_prt_origine,origine);
    addDataParameter(dpaIn,prm_prt_origine_primkey,origine_primkey);
    RemoteCommand:=TDARemoteCommand.Create(nil);
    RemoteCommand.RemoteService:=Self.GenericDBService;
    Result:=RemoteCommand.Execute(cmd_updatePrijsTabel, dpaIn, dpaOut);
    ...
  finally
    FreeAndNil(dpaIn);
    FreeAndNil(dpaOut);
    FreeAndNil(RemoteCommand);
  end;
end;

Hi,

I understood your point

in general, we can add overloads like

function Execute(aCommandName: string; aParamNames: array of string; aParamValues: array of Variant; out aOutputParameters: DataParameterArray): Integer; overload;
function Execute(aCommandName: string; aParamValues: array of Variant; out aOutputParameters: DataParameterArray): Integer; overload;

it can simplify code

Logged as bugs://D19478.

So just to be clear: At present no constant string identifiers with the daschema command names can be generated in a .pas file, correct?

Hi,

we have strongly typed access for tables only

bugs://D19478 was closed as fixed.