大虾请帮忙---很急

mygoodday 2001-06-11 03:49:00
有关stringgrid组件问题我不大会用.下面程序运行后,我在form3的edit1中输入字符后cells倒写进去了,不知为什么onsetedittext事件却没有反映呢?(是否用错事件?)
请大虾帮我改一下.(我主要想利用cells的内容变化,来进行对cells内容存贮的)


程序清单如下:

第一单元:
unit openandsaveu;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, StdCtrls, Grids;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
menumethod: TMenuItem;
menuwindow: TMenuItem;
menuitemnew: TMenuItem;
menuitemopen: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
sep3: TMenuItem;
filename1: TMenuItem;
filename2: TMenuItem;
filename3: TMenuItem;
filename4: TMenuItem;
menuitemread: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
menuitemsave: TMenuItem;
StringGrid1: TStringGrid;
procedure menuitemopenClick(Sender: TObject);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
alx,roY:integer;

implementation

uses openandsaveu2, openandsaveu3;

{$R *.DFM}

procedure TForm1.menuitemopenClick(Sender: TObject);

var
i,j:integer;
begin
//form13.show;
if opendialog1.Execute then
begin
if sep3.visible=false then
sep3.visible:=true;
for i:=0 to 3 do
begin
if menumethod.Items [5+i].Caption ='' then
begin

menumethod.Items [5+i].Caption :=opendialog1.filename;
menumethod.Items [5+i].Visible :=true;
break;
end
else
if menumethod.Items [5+i].Caption =opendialog1.FileName then
begin
j:=i;
while(j<3) and (menumethod.Items [6+j].Caption <>'')do
begin
menumethod.Items [5+j].Caption :=menumethod.Items [6+j].Caption ;
j:=j+1;
end;
menumethod.Items [5+j].Caption :=opendialog1.FileName ;
break;
end
else
if i=3then
begin
for j:=0 to 2 do
menumethod.Items [5+j].Caption :=menumethod.Items [6+j].Caption ;
menumethod.Items [8].Caption :=opendialog1.Filename;
end;
end;
end;
end;


procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
begin
savedialog1.execute;
if savedialog1.Execute and ( messagedlg('save file?',mtconfirmation,mbYesNoCancel,0)=mrYes)then
form2.show;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
alx:=acol;
roY:=arow;
form3.show;

end;

end.

第二单元:

unit openandsaveu2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm2 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
//procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

uses openandsaveu;

{$R *.DFM}

procedure TForm2.Button1Click(Sender: TObject);
var
i,j,k,lineNo:integer;
atextfile:system.text;
textLine:string;
begin
i:=strtoint(edit1.text);
j:=strtoint(edit2.text);

with form1 do
begin ////
if savedialog1.execute then
begin
assignfile(atextfile,savedialog1.filename);
rewrite(atextfile);
for k:=i to j do
begin
textline:=stringgrid1.cells[1,k];
writeln(atextfile,textline);
end;
closefile(atextfile);
end;
end;/////

end;

end.

第三单元:

unit openandsaveu3;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm3 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

uses openandsaveu;

{$R *.DFM}

procedure TForm3.Button1Click(Sender: TObject);
var
x,y:integer;
begin
x:=alx;y:=roY;
form1.stringgrid1.cells[x,y]:=edit1.text;
edit1.Clear ;
close;

end;

end.





...全文
46 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
mygoodday 2001-09-28
  • 打赏
  • 举报
回复
没人回答

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧