////////////////////////////////////// dll的代码
library strop;uses
SysUtils,
Classes;{$R *.res}
{返回字符在字符串中的位置}
function instr(sourcestr:pchar;ch:char):integer;stdcall;export;
var
len,i: integer;
begin
len := strlen(sourcestr);
for i := 0 to len-1 do
if sourcestr[i] = ch then
begin
result := i;
exit;
end;
result := -1;
end; exports
instr index 1 name 'myinstr' resident;begin
end.
//****************************************************************************
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;function instr(sourcestr:pchar;ch:char):integer;stdcall;external 'myinstr';
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
sourcestr,ch :string;
begin
sourcestr := edit1.Text;
ch := edit2.Text;
button1.Caption := intTostr(instr(pchar(sourcestr),char(ch[1])));
end;end.
library strop;uses
SysUtils,
Classes;{$R *.res}
{返回字符在字符串中的位置}
function instr(sourcestr:pchar;ch:char):integer;stdcall;export;
var
len,i: integer;
begin
len := strlen(sourcestr);
for i := 0 to len-1 do
if sourcestr[i] = ch then
begin
result := i;
exit;
end;
result := -1;
end; exports
instr index 1 name 'myinstr' resident;begin
end.
//****************************************************************************
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;function instr(sourcestr:pchar;ch:char):integer;stdcall;external 'myinstr';
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
sourcestr,ch :string;
begin
sourcestr := edit1.Text;
ch := edit2.Text;
button1.Caption := intTostr(instr(pchar(sourcestr),char(ch[1])));
end;end.
**
看看如何?
help!!!!!!!!!
谢谢各位,成功了。
等着我结贴给分