如何添加一个自己编写的过程? (100分)

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

volcanosh

Unregistered / Unconfirmed
GUEST, unregistred user!
过程直接自己写好后再在type中加入可以了吗?
但下面这段老是说Undeclareed identifier 'ResultShow',怎么解决?
type
TfrmMain = class(TForm)
lblResult: TLabel;
lblShow: TLabel;
MainMenu1: TMainMenu;
M1: TMenuItem;
mmiOpen: TMenuItem;
D1: TMenuItem;
E1: TMenuItem;
dlgOpen: TOpenDialog;
lblPort: TLabel;
lblTime: TLabel;
Timer1: TTimer;
comPa: TComm;
comPb: TComm;
procedure mmiOpenClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ReadScriptFile(filename:string);
procedure ResultShow(str:string);
private
{ Private declarations }
public
{ Public declarations }
end;

procedure ReadScriptFile(FileName:String);
var
strLine:string;
begin
Assignfile(ScriptFile,'ScriptFileName');
Reset(ScriptFile);
While NOT SeekEOF(ScriptFile) do
begin
readln(scriptfile,strline);
if copy(strline,1,1)='d' then ResultShow(strline);
//if copy(strline,1,1)='(' then Send(strline);
end;
closefile(ScriptFile);
end;
procedure ResultShow(str:string);
var
ResultLine:string;
i:integer;
begin
//i:=pos('d',str);
for i:=1 to length(str) do
begin
if str='s' then
lblResult.caption:=copy(str,2,i-1);
end;
end;
 
procedure ResultShow(str:string);

你这个过程只在上面声明了,没具体实现(定义)啊?
当然会报
Undeclareed identifier 'ResultShow'的错了
下面的那个procedure Resultshow应在前面加个类名frmMain
 
你的resultshow是放在frmmain中的那么代码段应该是
procedure TFrmmain.ResultShow(str:string);吧
 
那为什么procedure ReadScriptFile(filename:string)可以用呢?我也是对它调用的
procedure TfrmMain.FormCreate(Sender: TObject);
var
fname:string;
begin
if (Not fileexists('FileName.ini')) then mmiOpenClick(Sender);
Assignfile(ini,'FileName.ini');
Reset(ini);
Readln(ini,fname);
closefile(ini);
ScriptFileName:=copy(fname,10,length(fname)-9);
ReadScriptFile(ScriptFileName);
//showmessage(scriptfile);
end;
 
ResultShow 你在什么地方调用 的?

在定义前加上 类名, 其他类和引用该 unit的 的地方就都可以用。
 
真搞不懂你的ReadScriptFile还能用,
 
多人接受答案了。
 
顶部