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

請教各位前輩一個文字檔編輯的問題

尚未結案
citygood123
一般會員


發表:6
回覆:6
積分:2
註冊:2005-05-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-06-19 22:42:27 IP:218.170.xxx.xxx 未訂閱
請教各位前輩! 手邊有個txt檔或ini如下圖,想要設計一個表格形式的視窗編輯程式,能編輯此檔的內容並儲存, 但其中的=及逗號為資料類型的分隔符號不能更動及刪除,想請教一下其要如何寫呢?這點完全沒有思路...     發表人 - citygood123 於 2005/06/19 22:44:02
Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-06-19 22:58:28 IP:211.22.xxx.xxx 未訂閱
1.如果欄位不多,建議使用MaskEdit,格式化輸入至檔案容易控制。 2.如果欄位很多,建議使用多個下拉式選單(僅文數字部分),將配對選取結果,一一按照需求格式格式化後寫入檔案。 請參考! -----------------------------------------------
citygood123
一般會員


發表:6
回覆:6
積分:2
註冊:2005-05-29

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-06-20 20:18:35 IP:218.170.xxx.xxx 未訂閱
引言: 1.如果欄位不多,建議使用MaskEdit,格式化輸入至檔案容易控制。 2.如果欄位很多,建議使用多個下拉式選單(僅文數字部分),將配對選取結果,一一按照需求格式格式化後寫入檔案。 請參考! ----------------------------------------------- >< face="Verdana, Arial, Helvetica"> 您好:可以再說明確一點嗎? 如何使用MaskEdit?
Stallion
版主


發表:52
回覆:1600
積分:1995
註冊:2004-09-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-06-20 21:10:17 IP:211.22.xxx.xxx 未訂閱
引言: 您好:可以再說明確一點嗎? 如何使用MaskEdit?
請在網站裡搜尋MaskEdit範例太多了!另外Delphi線上說明也很清楚喔!< >練功自己修行一下,當真的遇到問題,把癥結點程式碼提出來,站裡的先進給你一點才會通!< > ----------------------------------------------- Creation is the fundation of promotion.
citygood123
一般會員


發表:6
回覆:6
積分:2
註冊:2005-05-29

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-06-28 07:08:33 IP:218.170.xxx.xxx 未訂閱
感謝Stallion的回答!! 最近重新思考這問題並試著寫了一小段,但仍有問題無法解決,因條件是寫入txt時其中的=及逗號為資料類型的分隔符號不能更動及刪除,也不能兩者都使用相同符號(既都使用=或,) 以下程式中當讀取時仍會將第三個欄位的資料讀在第二個欄位,有無方式巧可以將第三個欄位讀在正確欄位?麻煩知道的先進告知一下, 謝謝! nterface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids; type TForm1 = class(TForm) StringGrid1: TStringGrid; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} var modified : Boolean = False; Const datafile : String = 'goods.txt'; procedure TForm1.FormCreate(Sender: TObject); var i, count : Integer; F : textFile ; str : string; ans : array[1..3] of string; row : Integer; begin StringGrid1.RowCount := 2; StringGrid1.Cells[0,0] := '商品名稱'; StringGrid1.ColWidths[0] := 300; StringGrid1.Cells[1,0] := '售價'; StringGrid1.ColWidths[1] := 200; StringGrid1.Cells[2,0] := '供貨狀況'; StringGrid1.ColWidths[2] := 300; // if FileExists(datafile) then begin AssignFile(F,datafile); Reset(F); row := 1; try while not EOF(F) do begin Readln(F,str); count := 1; for i := 1 to 2 do ans[i] := ''; for i := 1 to length(str) do if str[i] <> '=' then ans[count] := ans[count] str[i] else count := count 1 ; StringGrid1.Cells[0,row] := ans[1]; StringGrid1.Cells[1,row] := ans[2]; StringGrid1.Cells[2,row] := ans[3]; Inc(row); StringGrid1.RowCount := row; end; finally CloseFile(F); end; end; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var i, row : Integer; F : textFile ; str : string; begin if modified then if MessageDlg('儲存?',mtConfirmation, mbOKCancel,0) = mrOK then Begin Assignfile(F,datafile); Rewrite(F); try for row := 1 to pred(StringGrid1.RowCount) do Begin str := ''; for i := 0 to 0 do str := str StringGrid1.Cells[i,row] '='; str := str StringGrid1.Cells[1,row]; for i := 1 to 1 do str := str StringGrid1.Cells[i,row] ','; writeln(F,str); end; finally Closefile(F); end; end; end; procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); begin modified := True; end; end.
goat
高階會員


發表:53
回覆:130
積分:134
註冊:2002-06-03

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-06-28 08:56:00 IP:202.168.xxx.xxx 未訂閱
我的做法請參考 來源使用TiniFile的方式讀入->塞入Table中處理(修改)->由Table寫回文字檔。 Delphi Help↓ The following example reads information from a file into three listboxes on a form. uses IniFiles; procedure TForm1.FormActivate(Sender: TObject); var AppIni: TIniFile; begin AppIni := TIniFile.Create('win.ini'); AppIni.ReadSections(ListBox1.Items); AppIni.ReadSection('Ports',Listbox2.Items); AppIni.ReadSectionValues('Ports',ListBox3.Items); AppIni.Free; end; 不過你好像貼錯地方了吧! 發表人 - goat 於 2005/06/28 08:57:31
系統時間:2024-05-19 15:57:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!