Home RAP
New Blog Posts: Merging Reports - Part 1 and Part 2

OnDrawCommandCreate event

edited December 2010 in RAP
Hi,

Please see code below, the program crashes when trying to access
aDrawCommand (TObject) passed from RAP in the OnDrawCommandCreate event.
aDrawCommand is always nil. What am I missing.

The following is some Rap passthru stuff I created. I then add a report and
just add a label in the detail section and assign the 2 lines of code in the
RAP section in the designer.

Thanks


//PASS - THRU
type
TmyDrillDownCommandCreate = class(TraSystemFunction)
public
class function Category: string; override;
procedure ExecuteFunction(aParams: TraParamList); override;
class function GetSignature: string; override;
class function HasParams: Boolean; override;
end;

TmyDrillDownCommandAction = class(TraSystemFunction)
public
class function Category: string; override;
procedure ExecuteFunction(aParams: TraParamList); override;
class function GetSignature: string; override;
class function HasParams: Boolean; override;
end;

TmyDrawInfo = class(TComponent)
private
FViewType: string;
FKeyValues: Variant;
public
constructor CreateDrawInfo(aOwner: TComponent; AViewType: string;
AKeyValues: Variant); virtual;
property ViewType: string read FViewType;
property KeyValues: Variant read FKeyValues;
end;

implementation

{ TmyDrillDownCommandCreate }
class function TmyDrillDownCommandCreate.Category: string;
begin
Result := 'My Stuff';
end;

procedure TmyDrillDownCommandCreate.ExecuteFunction(aParams: TraParamList);
var
ADrawCommand: TObject;
lsViewType: string;
lvKeyValue: Variant;
lDrawInfo: TmyDrawInfo;
begin
GetParamValue(0, ADrawCommand);
GetParamValue(1, lsViewType);
GetParamValue(2, lvKeyValue);

lDrawInfo := TmyDrawInfo.CreateDrawInfo(Form1, lsViewType, lvKeyValue);

{attach to draw command}
TComponent(aDrawCommand).Tag := Integer(lDrawInfo);
end;

class function TmyDrillDownCommandCreate.GetSignature: string;
begin
Result := 'procedure DrillDownCommandCreate(aDrawCommand: TObject;
AViewType: string; AKeyValues: Variant);';
end;

class function TmyDrillDownCommandCreate.HasParams: Boolean;
begin
Result := True;
end;

{ TmyDrillDownCommandAction }

class function TmyDrillDownCommandAction.Category: string;
begin
Result := 'My Stuff';
end;

procedure TmyDrillDownCommandAction.ExecuteFunction(aParams: TraParamList);
var
ADrawCommand: TObject;
lsViewType: string;
lvKeyValue: Variant;
lDrawInfo: TmyDrawInfo;
begin
GetParamValue(0, ADrawCommand);

lDrawInfo := TmyDrawInfo(TComponent(aDrawCommand).Tag);
lsViewType := lDrawInfo.ViewType;
lvKeyValue := lDrawInfo.KeyValues;

{attach to draw command}
TComponent(aDrawCommand).Tag := Integer(lDrawInfo);

//do my stuff here
end;

class function TmyDrillDownCommandAction.GetSignature: string;
begin
Result := 'procedure DrillDownCommandAction(const ADrawCommand:
TObject);';
end;

class function TmyDrillDownCommandAction.HasParams: Boolean;
begin
Result := True;
end;

{ TmyDrawInfo }
constructor TmyDrawInfo.CreateDrawInfo(aOwner: TComponent; AViewType:
string; AKeyValues: Variant);
begin
inherited Create(aOwner);
FViewType := AViewType;
FKeyValues := AKeyValues;
end;

//Runtime RAP Code
procedure Label1OnDrawCommandCreate(aDrawCommand: TObject);
begin
DrillDownCommandCreate(aDrawCommand, 'View1', 'FieldValue');
end;

procedure Label1OnDrawCommandClick(aDrawCommand: TObject);
begin
DrillDownCommandAction(ADrawCommand);
end;

Comments

  • edited December 2010
    This issue is being researched. For now, as a work around, try using a local
    variable to call the pass-thru functions.

    Example:

    var
    lDrawCommand: TObject;
    begin
    lDrawCommand := aDrawCommand;
    DrillDownCommandCreate(lDrawCommand , 'View1', 'FieldValue');
    end;



    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited December 2010
    Thanks for the workaround.

This discussion has been closed.