一个delphi调用动态库的程序,大家帮忙看看(100分)

  • 主题发起人 主题发起人 viclouis
  • 开始时间 开始时间
V

viclouis

Unregistered / Unconfirmed
GUEST, unregistred user!
begin
dl_ClearStack; // Deletes and frees all spectrums in stack. After this STackPointer=-1;
if not dl_ShowEnginePanelModal then // input interferogram to stack position 0
exit;
uDrawGraph(0,ChartInterferogram); // draws data (Interferogram) from stack position 0
if dl_GetSpectrumMode(0)=smInterferogram then // if data in position 0 are Interferogram mode (option dialog->Preferences->not "auto transform")
begin
dl_ToMode(0,smSpectrum); // converts data from stack position 0 (Interferogram) to Spectrum and stores it in position 1
uDrawGraph(1,ChartSpectrum); // draws data (Spectrum) from stack position 1
uSaveJCamp(1); // saves Spectrum data from stack position 1
uGetJCAMP_toMemo(1); // convertes data in stack pos 1 to JCamp text and shows in Memo
end else if dl_GetSpectrumMode(0)=smSpectrum then
//if data in position 0 are SPectrum.Option dialog->Preferences->"auto transform",
// after acquiring interferogram, data are transformed to Spectrum
begin
uGetJCAMP_toMemo(0); // convertes data in stack pos 0 to JCamp and shows in Memo
uSaveJCamp(0); // saves Spectrum data from stack position 0
end;
end;

procedure TForm2.uDrawGraph(aStackPos:integer;aChart:TChart);
var pp:S2Ptr;
ii,aCnt,aPts : integer;

procedure aPutAxesValues(aAxis:TChartAxis;aMin,aMax:double);
begin
if aMin>aMax then
aMin:=aMax-0.0000001;
if aAxis.minimum>aAxis.maximum then
aAxis.minimum:=aAxis.maximum-0.0000001;
if aAxis.minimum>aMax then
begin
aAxis.minimum:=aMin;
aAxis.maximum:=aMax;
end else // if aAxis.maximum<aMin then
begin
aAxis.maximum:=aMax;
aAxis.minimum:=aMin;
end;
end;

procedure aPrepareChartAxesAndTitle;
var
aName : string;
aXMin,aXMax,aYMin,aYMax : double;
aMode : TSpectrumMode;
begin
aXMax:=dl_GetXMax(aStackPos); // maximum X value in data array in datastack, position aStackPos
aXMin:=dl_GetXMin(aStackPos); // minimum X value
aYMax:=dl_GetYMax(aStackPos); // maximum Y value
aYMin:=dl_GetYMin(aStackPos); // minimum Y value
aMode:=dl_GetSpectrumMode(aStackPos);
aName:=dl_GetSpectrum_Mode_name(aStackPos);
aPutAxesValues(aChart.BottomAxis,aXMin,aXMax);
if (axMax-axMin)<2 then
aChart.BottomAxis.increment:=(axMax-axMin)/10000;
aPutAxesValues(aChart.LeftAxis,aYMin,aYMax);
aChart.LeftAxis.increment:=(aYMax-aYMin)/10000;
aChart.LeftAxis.AxisValuesFormat:='###0.#####';//'0.00000';
aChart.BottomAxis.AxisValuesFormat:='###0.#####';//'0.00000';
aChart.BottomAxis.Inverted:=not(amode in [smInterferogram,smOther,smEmpty]);
aChart.Series[0].Clear;
aChart.Title.Text.Clear;
aChart.Title.Text.Add(aName);
end;

begin
aPrepareChartAxesAndTitle;

aCnt:=dl_GetPointsCount(aStackPos);
if aCnt>0 then
begin
getmem(pp,aCnt*(sizeof(TS2Rec)+8));
try
aPts:=dl_GetGrfPoints(aStackPos,aCnt,pp);
for ii:=0 to aPts-1 do
aChart.Series[0].AddXY(pp^[ii].x,pp^[ii].y,'',clTeeColor);
finally
freemem(pp);
end;
end;
end;

procedure TForm2.uGetJCAMP_toMemo(aStackPos:integer);
var pp : pchar;
aSize : integer;
begin
aSize:=dl_ConvJCampGetSize(aStackPos);
if aSize<=0 then
exit;
getmem(pp,aSize+1);
try
dl_ReadJCamp(aStackPos,pp);
MemoJCampData.lines.Text:=pp;
finally
freemem(pp,aSize+1);
end;
end;

procedure TForm2.ShowOptionsDialog1Click(Sender: TObject);
begin //
dl_ShowOptionDialog(0); // shows optiondialog modal, open page 0
end;

procedure TForm2.ShowSystemState1Click(Sender: TObject);
begin
case TSystem_State(dl_GetSystemState) of
stOnLine : showmessage('OnLine');
stOffLine : showmessage('OffLine');
stBusy : showmessage('Busy');
end;
end;

procedure TForm2.uSaveJCamp(aStackPos:integer);
var cc : array[0..200] of char;
begin //
Savedialog1.filename:=ChangeFileext(extractfilename(dl_GetShortName(aStackPos)),'.DX');
if not Savedialog1.Execute then
exit;
dl_saveToFile(aStackPos,strpcopy(cc,Savedialog1.filename));
end;

end.
我想问一下,调用dl_ShowEnginePanelModal 函数,需要提前分配内存马?我是学vc的,仿照这个例子调用delphi的动态库
 
调用DLL函数有这么复杂吗?
 
对阿,我用vc调就老是崩掉,delphi又不是很懂,所以请大家帮我看看,调用 dl_ShowEnginePanelModal ,是否需要什么前提
 
后退
顶部