| Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате |
| Форум программистов > Delphi: Для новичков > Добавлять значения в StringGrid |
| Автор: harakteristika 7.5.2010, 16:19 | ||||
| Добрый вечер. У мнея есть такой вопрос. Как можно сделать чтоб в Stringgrid отображались данные которые я ввожу на другой форме. На второй форме находятся Edit и DateTimePicker ну и соответственно 2 кнопки ок и отмена. Нашел пример а разобраться немогу.
begin // Glavnay_s.StringGrid1.Items.Clear; AssignFile(dbfile,dbname); t:=TStringList.create; //создаём класс i:=0; count:=0; if fileexists(dbname) then Reset(dbfile) else exit; while not eof(dbfile) do begin readln(dbfile); Inc(count); end; Reset(dbfile); Setlength(MyDBF,count); while not eof(dbfile) do begin readln(dbfile,str); t.text:=stringReplace(str,':',#13#10,[rfReplaceAll]); MyDBF[i].name:=t[0]; MyDBF[i].tel:=t[1]; MyDBF[i].number_doc:=t[2]; MyDBF[i].date_doc:=t[3]; MyDBF[i].date_use:=t[4]; MyDBF[i].fact_use:=t[5]; Ниже написано мои доработки // Glavnay_s.StringGrid1.Items.Add(MyDBF[i].name); inc(i); StringGrid1.Cells[0,0] := '№ п.п.'; StringGrid1.Cells[1,0] := '№ КД'; StringGrid1.Cells[1,1] := '1234567-1234'; // StringGrid1.Cells[2,0] := 'ФИО'; StringGrid1.Cells[2,1] := 'Крайнюченко Александр Юрьевиексчк'; // StringGrid1.Cells[3,0] := 'Телефон'; StringGrid1.Cells[3,1] := '+79181234567'; // StringGrid1.cells[4,0] := 'Дата КД'; StringGrid1.cells[4,1] := '12.12.2009'; // StringGrid1.Cells[5,0] := 'Пред. по ЦИ'; StringGrid1.Cells[5,1] := '12.02.2010'; // StringGrid1.Cells[6,0] := 'Факт по ЦИ'; StringGrid1.Cells[6,1] := '11.02.2010'; end; Это на главной форме. А вот на второй
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Mask, ComCtrls, Buttons; type TAdd_s = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; DateKD1: TDateTimePicker; DateKD2: TDateTimePicker; DateKD3: TDateTimePicker; FIO: TEdit; SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; Tel: TEdit; KD: TEdit; procedure Glavnay_sAction7Execute(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; TRecordDB = record name: string; site: string; login: string; pass: string; comment: string; end; TDBfile = array of TrecordDB; var mydbf: TDBfile; dbfile: textfile; i, count: integer; str: string; t:TStringList; const dbname = 'my_basa.dbf'; var Add_s: TAdd_s; implementation {$R *.dfm} procedure TAdd_s.Glavnay_sAction7Execute(Sender: TObject); begin Add_s.Show; end; procedure TAdd_s.SpeedButton1Click(Sender: TObject); var I: Integer; EditData: TStringList; begin EditData := TStringList.Create; for I := 0 to ComponentCount - 1 do if (Components[i] is TEdit) then (Components[i] as TEdit).Text := 'новый текст' end; procedure TAdd_s.SpeedButton2Click(Sender: TObject); begin Close; end; end. |
| Автор: ~FoX~ 7.5.2010, 16:28 | ||
| harakteristika, Выбраси этот пример и возьми две вещи: 1. Любую книжку по делфи... 2. Встроенных хелп...
|
| Автор: harakteristika 7.5.2010, 16:36 |
| А что необходимо сделать чтоб 2 форма закрывалась после нажатия ОК? |
| Автор: ~FoX~ 7.5.2010, 16:40 | ||
|
| Автор: harakteristika 7.5.2010, 16:51 |
| ~FoX~, Огромное тебе спасибо!!!! |
| Автор: ~FoX~ 7.5.2010, 17:25 |
| harakteristika, Не за что )))) [off]Совет: Почитай любую книгу по ООП, любого автора и по любому языку.... Хотя бы идеологию поймешь.... Научись пользоваться справкой... И поиском.... Первые шаги в программировании написаны на каждом углу..... Ну и, конечно, обращайся, если что понадобится |