спасибо за помощь,не все понял что тут посоветовали но многое пригодилось.Вот только с поиском и сортировкой проблема.Я обозначил ораньжевым место где сравнивается 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
{ Private declarations }
public
{ Public declarations }
end;
var
TTemp :string; {описали TTemp}
Form1: TForm1;
implementation
{$R *.dfm}
// Save a TStringGrid to a file
procedure SaveStringGrid(StringGrid: TStringGrid; const Temp: string);
var
f: TextFile;
i, k: Integer;
begin
AssignFile(f, temp);
Rewrite(f);
with StringGrid do
begin
// Write number of Columns/Rows
Writeln(f, ColCount);
Writeln(f, RowCount);
// loop through cells
for i := 0 to ColCount - 1 do
for k := 0 to RowCount - 1 do
Writeln(F, Cells[i, k]);
end;
CloseFile(F);
end;
// Load a TStringGrid from a file
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
// Get number of columns
Readln(f, iTmp);
ColCount := iTmp;
// Get number of rows
Readln(f, iTmp);
RowCount := iTmp;
// loop through cells & fill in values
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
{ On the last row}
Grid.RowCount := Grid.RowCount - 1
else
begin
{ Not the last row}
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 { Found!}
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.