vensim_get_val called from Delphi
Posted: Fri Apr 04, 2008 1:55 pm
Dear colleagues,
when trying to get variable values from an ongoing vensim simulation into a Delphi 5.0-coded application I can't make the function vensim_get_val() work. However, after simulation it's easy to access the same variables with vensim_get_data().
To be more precise, here are the relevant Delphi code fragments:
// global type and variable definitions
type
TSingleTimeline = array[1..2000] of Single;
var
SumSubstrateHeight: TSingleTimeLine;
timeval: TSingleTimeline;
// procedures
procedure A;
var result: Integer;
begin
result := vensim_command('SIMULATE>RUNNAME|Current');
result := vensim_command('MENU>RUN|O');
result := vensim_get_data('Current', 'Sum Substrate Height', 'Time',
@SumSubstrateHeight[1], @timeval[1], 2000);
end;
procedure B;
var result, i: Integer;
CurrentTime, CurrentValue: Single;
begin
result := vensim_command('SIMULATE>RUNNAME|Current');
result := vensim_start_simulation(1,0,1);
if result = 1 then begin
while result = 1 do begin
i := vensim_get_val('Time', @CurrentTime);
i := vensim_get_val('Sum Substrate Height', @CurrentValue);
result := vensim_continue_simulation(20);
end;
result := vensim_finish_simulation();
end;
end;
While procedure A works perfectly, procedure B fails completely. When coming into the while-loop for the first time vensim_get_val() returns 0. At the second time the computer hangs or reports an access violation message. Can anybody tell me where the mistake is in procedure B?
Greetings
Peter
when trying to get variable values from an ongoing vensim simulation into a Delphi 5.0-coded application I can't make the function vensim_get_val() work. However, after simulation it's easy to access the same variables with vensim_get_data().
To be more precise, here are the relevant Delphi code fragments:
// global type and variable definitions
type
TSingleTimeline = array[1..2000] of Single;
var
SumSubstrateHeight: TSingleTimeLine;
timeval: TSingleTimeline;
// procedures
procedure A;
var result: Integer;
begin
result := vensim_command('SIMULATE>RUNNAME|Current');
result := vensim_command('MENU>RUN|O');
result := vensim_get_data('Current', 'Sum Substrate Height', 'Time',
@SumSubstrateHeight[1], @timeval[1], 2000);
end;
procedure B;
var result, i: Integer;
CurrentTime, CurrentValue: Single;
begin
result := vensim_command('SIMULATE>RUNNAME|Current');
result := vensim_start_simulation(1,0,1);
if result = 1 then begin
while result = 1 do begin
i := vensim_get_val('Time', @CurrentTime);
i := vensim_get_val('Sum Substrate Height', @CurrentValue);
result := vensim_continue_simulation(20);
end;
result := vensim_finish_simulation();
end;
end;
While procedure A works perfectly, procedure B fails completely. When coming into the while-loop for the first time vensim_get_val() returns 0. At the second time the computer hangs or reports an access violation message. Can anybody tell me where the mistake is in procedure B?
Greetings
Peter