View Issue Details

IDProjectCategoryView StatusLast Update
0001855JEDI VCL00 JVCL Componentspublic2004-07-13 04:37
ReporteranonymousAssigned Toobones 
PrioritynormalSeveritytextReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0001855: TJvInterpreter, var Objects passed as parameter
DescriptionHello,

I'm trying to get the Interpreter stuff working with this stuff...


In my project, I have this code in Editor.pas:

[code]
function GetActiveEditor(var AEditor: TEditorForm): Boolean;
begin
  Result := False;
  
  with Application.MainForm do
  begin
    if ActiveMDIChild is TEditorForm then
    begin
      // TEditorForm is just a derived class from TForm
      AEditor := ActiveMDIChild as TEditorForm;
      Result := ActiveMDIChild is TEditorForm;
    end;
  end;
end;
[/code]



The code, to let the interpreter know about it, is this:

[code]
procedure Interpreter_GetActiveEditor(var Value: Variant; Args: TJvInterpreterArgs);
begin
  // is this correct this way?
  Value := GetActiveEditor(TEditorForm(TVarData(Args.Values[0]).VPointer));
end;

procedure RegisterJvInterpreterAdapter(JvInterpreterAdapter: TJvInterpreterAdapter);
const
  cUnit = 'Editor';
begin
  with JvInterpreterAdapter do
  begin
    AddClass(cUnit, TEditorForm, 'TEditorForm');
    AddFunction(cUnit, 'GetActiveEditor', Interpreter_GetActiveEditor, 1, [varEmpty], varEmpty);
  end;
end;

initialization
  RegisterJvInterpreterAdapter(GlobalJvInterpreterAdapter);
[/code]




And I use this script:
[code]
unit Unit1;

Procedure main;
var
 Editor: TEditorForm;
begin
  // if I don't "nil" the variable here
  // the interpreter gives expression errors
  Editor := nil;

  if GetActiveEditor(Editor) then
  begin
    if Editor <> nil then
      ShowMessage('Got it!');
  end;
end;

end.
[/code]


The interpreter calls GetActiveEditor (I did set a breakpoint, so this works), but I didn't find any way store the Editor object in the var parameter.

I studied JvInterpreter_* units and tested an half day, but didn't find any solution yet.


I wonder if this supported?


Any advice highly appreciated, thanks in advance!

Peter
TagsNo tags attached.

Activities

2004-06-13 12:34

 

InterpreterTest.zip (3,554 bytes)

AlexeiR

2004-06-21 02:56

reporter   ~0004589

Try using varByRef:
AddFunction(cUnit, 'GetActiveEditor', Interpreter_GetActiveEditor, 1, [varByRef], varEmpty);

anonymous

2004-06-21 08:38

viewer   ~0004594

Hi AlexeiR,

thanks for the info!

I also changed the 'Interpreter_GetActiveEditor' procedure to get it to work. It looks now like this:

[code]
procedure Interpreter_GetActiveEditor(var Value: Variant; Args: TJvInterpreterArgs);
var
  Editor: TEditorForm;
begin
  //Value := GetActiveEditor(TEditorForm(TVarData(Args.Values[0]).VPointer));

  Editor := nil;
  Value := GetActiveEditor(Editor);
  Args.Values[0] := O2V(Editor);
end;
[/code]

And together with the varByRef parameter, it finally works!

Is this is correct way to do this btw? I just ask, because I didn't find any documentation on it and 'm not sure if it is. :)

Thanks again!



JEDI Team - this issue can be closed though

obones

2004-07-13 04:37

administrator   ~0004756

As requested by the author, this bug is now resolved

Issue History

Date Modified Username Field Change
2004-06-13 12:18 anonymous New Issue
2004-06-13 12:34 anonymous File Added: InterpreterTest.zip
2004-06-21 02:56 AlexeiR Note Added: 0004589
2004-06-21 08:38 anonymous Note Added: 0004594
2004-07-13 04:37 obones Status new => resolved
2004-07-13 04:37 obones Resolution open => fixed
2004-07-13 04:37 obones Assigned To => obones
2004-07-13 04:37 obones Note Added: 0004756