
19.03.2010, 17:19
|
 |
Продвинутый
|
|
Регистрация: 02.06.2008
Адрес: Бендеры ПМР
Сообщения: 754
Репутация: 2446
|
|
Как то так...
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
temp,temp1:string;
begin
//Если число столбцов не четное то
if(StringGrid1.ColCount mod 2 = 1) then
//переменной приравнивается последняя ячейка первого столбца
temp1 := StringGrid1.Cells[StringGrid1.colcount-1,0];
//Кажый второй столбец
for i := 0 to stringgrid1.ColCount div 2 do begin
//Стандартный алгоритм обмена позициями
//a=1 b=2 -->c:=a, a:=b, b:=c-->a=2, b=1
temp := stringgrid1.Cells[2*i,0];//c:=a
StringGrid1.Cells[2*i,0]:= StringGrid1.Cells[2*i+1,0];//a:=b
StringGrid1.Cells[2*i+1,0] := temp;//b:=c
end;
//Если число столбцов не четное то
if(StringGrid1.ColCount mod 2 = 1) then
//последней ячейке первого столбца приравнять переменную
StringGrid1.Cells[StringGrid1.colcount-1,0] := temp1;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
//Генератор случайный чисел
randomize;
//Первый столбец заполнить случайными до 128
for i:= 0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[i,0] := inttostr(random(128));
end;
end.
__________________
В начале был Бит, потом Байт и только потом появилось Слово...
|