線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2229
推到 Plurk!
推到 Facebook!

請問如何得到stringgrid中某些cell的資料被修改

尚未結案
m510201
一般會員


發表:2
回覆:0
積分:0
註冊:2005-07-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-25 02:52:36 IP:61.57.xxx.xxx 未訂閱
請問各位先進 因為使用stringgrid做為資料輸入及顯示,需知道那些欄位已修改,以便檢查及回存資料庫,可是如何得到stringgrid中某些cell的資料被修改,或者可介紹有哪些stringgird元件有此功能,請大家幫忙,先在此謝謝
chris_shieh
高階會員


發表:46
回覆:308
積分:240
註冊:2004-04-26

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-25 16:49:24 IP:203.70.xxx.xxx 未訂閱
自己檢查如何    利用array of array of string來儲存變更前的資料    
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, Buttons, StdCtrls, Grids;    type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    StringGrid2: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    grids:array of array of String;
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    {$R *.dfm}    procedure TForm1.FormCreate(Sender: TObject);
var
  i,j:integer;
begin
  //把所有StringGrid1內資料記錄下來
  SetLength(grids, StringGrid1.ColCount);
  for i := 0 to Length(grids)-1 do
  begin
    SetLength(grids[i], StringGrid1.Cols[i].Count);
    for j := 0 to StringGrid1.Cols[i].Count-1 do
    begin
      grids[i][j]:=StringGrid1.Cells[i,j];
    end;
  end;
end;    procedure TForm1.Button1Click(Sender: TObject);
var
  i,j:integer;
begin
  //隨便填值
  for i := 0 to StringGrid1.ColCount-1 do
  begin
    for j := 0 to StringGrid1.Cols[i].Count-1 do
    begin
      StringGrid1.Cells[i,j]:=IntToStr(i)   ','   IntToStr(j);
    end;
  end;    end;    procedure TForm1.Button2Click(Sender: TObject);
var
  i,j:integer;
  Text:String;
begin
  //檢查變更過的填入StringGrid2
  for i := 0 to Length(grids)-1 do
  begin
    for j := 0 to Length(grids[i])-1 do
    begin
      if (grids[i][j]<>StringGrid1.Cells[i,j]) then
        StringGrid2.Cells[i,j]:=StringGrid1.Cells[i,j];
    end;
  end;
end;    end.    
@瞭解越多.懂得越少@
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-07-26 09:25:51 IP:61.222.xxx.xxx 未訂閱
提供幾點建議: 1. 如果僅偵測輸入Cells 時的改變,可用 SetEditText 事件。 2. 若欲涵蓋 Cells 發生異動。 可繼承 TstringGrid = Class(Grids.TStringGrid),並建立同名屬性 Cells 在 SetCells 及GetCells 方面 ,才修改父係的 Cells 。 從中建立 OnChange 事件。 不過對於Tstrings.assign卻是無效的。 其他元件可至 Torry's 網站查詢。 或直接修改Grids 源碼。自己斟酌。 參考 ~~~~~~~~~~~ 難得聰明,常常糊塗。 ~~~~~~~~~~~
malanlk
尊榮會員


發表:20
回覆:694
積分:577
註冊:2004-04-19

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-07-26 11:17:56 IP:203.69.xxx.xxx 未訂閱
可以這樣玩玩看, 用這種方式記下來還可以做出"還原"效果, 如果要做還原效果請不要忘了先要處理 OnSetEditText 及 SelectCell Event (先設為 nil 再設回來) 不然永遠還原不完....  
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;    type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Memo1: TMemo;
    procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
      const Value: String);
    procedure Button1Click(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    {$R *.dfm}    var
  theOrgValue: String = '';
  theCellValueChanged: Boolean = False;
  theModifiedStringList: TStringList;    procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: String);
begin
  if (not theCellValueChanged) and (theOrgValue<>Value) then
  begin
    theCellValueChanged := True;
    theModifiedStringList.Add(Format('%d,%d,%s',[ACol,ARow,theOrgValue]));
  end;
end;    procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  Memo1.Lines.Clear;
  for i:=0 to theModifiedStringList.Count-1 do
  begin
    Memo1.Lines.Add(theModifiedStringList[i]);
  end;
end;    procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  theOrgValue := StringGrid1.Cells[ACol,ARow];
  theCellValueChanged := False;
end;    initialization
  theModifiedStringList := TStringList.Create;
finalization
  theModifiedStringList.Free;    end.
SamSam1230
中階會員


發表:128
回覆:178
積分:65
註冊:2004-12-23

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-09-08 11:37:23 IP:218.103.xxx.xxx 未訂閱
可以試試到這個看看 http://www.tmssoftware.com/ 但都不是免費的
m510011
一般會員


發表:18
回覆:18
積分:7
註冊:2002-05-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-11-08 13:02:45 IP:61.59.xxx.xxx 未訂閱
感謝各位的解答,因為工作上忙碌忘了結案,請大家海涵喽!
系統時間:2024-05-06 18:50:08
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!