спасибо за помощь,не все понял что тут посоветовали но многое пригодилось.Вот только с поиском и сортировкой проблема.Я обозначил ораньжевым место где сравнивается Edit1 и Stringgrid.А там еще нужно что бы лишние строки удалялись.как это возможно сделать через массив?
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TFriendGrid = class(TStringGrid);
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
CheckBox1: TCheckBox;
Button4: TButton;
Button5: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
public
end;
var
TTemp :string;
Form1: TForm1;
implementation
procedure SaveStringGrid(StringGrid: TStringGrid; const Temp: string);
var
f: TextFile;
i, k: Integer;
begin
AssignFile(f, temp);
Rewrite(f);
with StringGrid do
begin
Writeln(f, ColCount);
Writeln(f, RowCount);
for i := 0 to ColCount - 1 do
for k := 0 to RowCount - 1 do
Writeln(F, Cells[i, k]);
end;
CloseFile(F);
end;
procedure LoadStringGrid(StringGrid: TStringGrid; const temp: string);
var
f: TextFile;
iTmp, i, k: Integer;
strTemp: String;
begin
AssignFile(f, Temp);
Reset(f);
with StringGrid do
begin
Readln(f, iTmp);
ColCount := iTmp;
Readln(f, iTmp);
RowCount := iTmp;
for i := 0 to ColCount - 1 do
for k := 0 to RowCount - 1 do
begin
Readln(f, strTemp);
Cells[i, k] := strTemp;
end;
end;
CloseFile(f);
end;
procedure GridDeleteRow(RowNumber: Integer; Grid: TstringGrid);
var
i: Integer;
begin
Grid.Row := RowNumber;
if (Grid.Row = Grid.RowCount - 1) then
Grid.RowCount := Grid.RowCount - 1
else
begin
for i := RowNumber to Grid.RowCount - 1 do
Grid.Rows[i] := Grid.Rows[i + 1];
Grid.RowCount := Grid.RowCount - 1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SaveStringGrid(StringGrid1, 'c:\temp.txt');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
LoadStringGrid(StringGrid1, 'c:\temp.txt');
end;
procedure TForm1.Button3Click(Sender: TObject);
var R,I: Integer;
begin
for R:= 0 to StringGrid1.RowCount-1 do
begin
i := StringGrid1.Rows[R].IndexOf('Text');
if i>=0 then
begin
StringGrid1.Row:=R;
StringGrid1.Col:=i;
end;
end;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
f: TextFile;
I, k : Integer;
edit1 : String;
temp: string;
begin
AssignFile(f, temp);
reset(f);
begin
with StringGrid1 do
for I := 0 to ColCount - 1 do
for k:= 0 to RowCount - 1 do
if Cells[I,k] = edit1 then
readln(F, edit1);
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
with TFriendGrid(StringGrid1) do
begin
MoveRow(Row, RowCount - 1);
RowCount := RowCount - 1
end;
end;
end.