?? main.~pas
字號:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons, FileCtrl, ComCtrls, Db, Halcn6DB, Grids,
AppEvnts;
type
TfrmMain = class(TForm)
FileListYY: TFileListBox;
PageControl1: TPageControl;
tabSystem: TTabSheet;
tabDB: TTabSheet;
ListBox1: TListBox;
ListBox2: TListBox;
tableMain: THalcyonDataSet;
Grid01: TStringGrid;
StatusBar: TStatusBar;
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure YYBtnClick(Sender: TObject);
procedure GenObject(n: integer; Sender: TObject);
procedure LoadYoYo(n: integer);
procedure ydAppendRecord;
procedure ydAssignDB(dbFileName: string);
procedure yiShowDB;
procedure ydOpenDB;
procedure ydCloseDB;
procedure ydGetBottomID; //獲得數據庫最大的ID
procedure ydSaveRecord; //指定存盤
procedure ydEditRecord; //修改指定的記錄
procedure ydDelRecord; //指定ID刪除
procedure yiShowInputWindow(s: string); //顯示編輯單條記錄窗口
procedure yiShowStatus(s:string); //在狀態欄顯示信息
end;
var
frmMain: TfrmMain;
implementation
{$R *.DFM}
uses Tools, yyTools, JBStr, uinput;
//1999.9.25
//獲得數據庫最大的ID
procedure TfrmMain.ydGetBottomID;
begin
gnBottomID := 0;
ydOpenDB; //打開數據庫
//判斷是否數據庫記錄為空
if tableMain.RecordCount <= 0 then begin
gnBottomID := 0;
end
else begin
tableMain.last;
gnBottomID := StrToInt(tableMain.fieldbyname('ID').value);
end;
ydCloseDB; //關閉數據庫
end;
//1999.9.17. 9.21. 9.24.
//根據yy1文件生成的按鈕的事件
procedure TfrmMain.YYBtnClick(Sender: TObject);
var
sCommand, sSource: string;
i: integer;
ln1: integer;
begin
ln1 := (Sender as TBitBtn).tag; //獲得現在是第幾個按鈕
//開始解碼循環
i := 0;
while i < gaYYBtn[ln1].YYSourceLine do
begin
gnYPoint := i + 1; //記錄當前執行到第幾行的指針
sSource := gaYYBtn[ln1].YYSource[gnYPoint]; //臨時記錄一行yy語言
sCommand := GetFirstWord(sSource, [' ']);
if sCommand = 'ysCloseApp' then
begin
ysCloseApp;
end;
if sCommand = 'ysCopyFile' then
begin
ysCopyFile(sSource);
end;
if sCommand = 'ydAppendRecord' then
begin
ydAppendRecord;
end;
if sCommand = 'yiShowDB' then
begin
yiShowDB;
end;
if sCommand = 'yiShowInputWindow' then
begin
yiShowInputWindow(sSource);
end;
if sCommand = 'yiShowStatus' then
begin
yiShowStatus(sSource);
end;
if sCommand = 'ydEditRecord' then
begin
ydEditRecord;
end;
if sCommand = 'ydSaveRecord' then
begin
ydSaveRecord;
end;
if sCommand = 'ydDelRecord' then
begin
ydDelRecord;
end;
i := i + 1;
end;
end;
//1999.9.17. 9.21. 9.23.
//讀入yy1文件,分析對象
procedure TfrmMain.LoadYoYo(n: integer);
var
i: integer;
begin
try
gsList := TStringList.Create;
gsList.LoadFromFile(ButPath + FileListYY.Items[n - 1]);
gsButCaption := gsList.Strings[0];
gsButBMPFile := gsList.Strings[1];
gsButHint := gsList.Strings[2];
//第幾個tab
gnButTab := StrToInt(ExtractWord(1, gsList.Strings[3], [' ']));
//tab上第幾個按鈕
gnButTabOrder := StrToInt(ExtractWord(2, gsList.Strings[3], [' ']));
//讀入每個yy1腳本語言的源代碼
for i := 6 to gsList.Count - 1 do
begin
gaYYBtn[n].YYSource[i - 5] := gsList.Strings[i];
end;
gaYYBtn[n].YYSourceLine := gsList.Count - 6; //yy腳本語言的行數
AppendLog('讀入對象:' + gsButCaption);
finally
gsList.Free;
end;
end;
//1999.9.17. 9.24.
//生成按鈕對象
procedure TfrmMain.GenObject(n: integer; Sender: TObject);
begin
gBut := TBitBtn.Create(self);
gBut.Left := gnPanXOff + (gnButTabOrder - 1) * 80;
gBut.Top := gnPanYOff;
gBut.caption := gsButCaption;
gBut.NumGlyphs := 2;
gBut.Glyph.LoadFromFile(ButBMPPath + gsButBMPFile);
gBut.Tag := n;
gBut.Hint := gsButHint;
if gnButTab = 0 then gBut.Parent := tabDB;
if gnButTab = 1 then gBut.Parent := tabSystem;
gBut.OnClick := YYBtnClick; //事件掛鉤
AppendLog('生成對象:' + gsButCaption);
end;
//窗口初始化事件
//1999.9.25. edit
procedure TfrmMain.FormCreate(Sender: TObject);
var
i: integer;
begin
InitYoYo; //初始化
FileListYY.Directory := ButPath; //制定yy1文件的路徑
gnYYCount := FileListYY.Items.Count; //計算yy1文件的數量
tableMain.DatabaseName := GetAppPath;
ydAssignDB('money.dbf');
ydGetBottomID;
//按照yy1文件的數量進行循環
for i := 1 to gnYYCount do
begin
gnYYCurrent := i; //當前的yy1對象是第幾個
LoadYoYo(i); //讀入對象申明文件
GenObject(i, Sender); //生成對象
end;
end;
//ydAssignDB 數據庫文件名關聯
//1999.9.24. 9.25.
procedure TfrmMain.ydAssignDB(dbFileName: string);
begin
if FileExists(GetAppPath+dbFileName)=false then
begin
gnErr:=101; //文件不存在
AppendLog('指定文件:'+dbFileName+'不存在');
Exit;
end;
tableMain.DatabaseName := GetAppPath;
tableMain.tableName := dbFileName;
end;
//ydAppendRecord 追加記錄
//1999.9.25.
procedure TfrmMain.ydAppendRecord;
var
i: integer;
begin
try
listbox1.Items.Clear;
listbox2.Items.Clear;
listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入數據庫字段文本文件
listbox2.Items.LoadFromFile(GetAppPath + 'rec.txt'); //引入數據庫字段新增記錄文本文件
ydAssignDB('money.dbf');
ydOpenDB;
tableMain.Append;
//按照字段文本文件插入記錄
for i := 0 to listbox1.items.count - 1 do begin
tableMain.FieldByName(listbox1.items[i]).value := listbox2.items[i];
end;
tableMain.Post;
ydCloseDB; //關閉數據庫
except
gnErr:=102;//追加記錄發生錯誤
end;
end;
//ydAppendRecord 指定ID存盤記錄
//1999.9.25.
procedure TfrmMain.ydSaveRecord;
var
i: integer;
iID: integer;
begin
listbox1.Items.Clear;
listbox2.Items.Clear;
listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入數據庫字段文本文件
listbox2.Items.LoadFromFile(GetAppPath + 'rec.txt'); //引入數據庫字段新增記錄文本文件
ydAssignDB('money.dbf');
ydOpenDB;
iID := strtoint(Listbox2.items[0]);
while not tableMain.eof do
begin
if iID = StrToint(tableMain.fieldbyname('ID').value) then
begin
tableMain.edit;
//按照字段文本文件插入記錄
for i := 0 to listbox1.items.count - 1 do
begin
tableMain.FieldByName(listbox1.items[i]).value := listbox2.items[i];
end;
tableMain.Post;
end;
tableMain.next;
end;
ydCloseDB; //關閉數據庫
end;
//ydDelRecord 指定ID刪除
//1999.9.25.
procedure TfrmMain.ydDelRecord;
var
iID: integer;
begin
listbox2.Items.Clear;
listbox2.Items.LoadFromFile(GetAppPath + 'rec.txt'); //引入數據庫字段新增記錄文本文件
ydAssignDB('money.dbf');
ydOpenDB;
iID := strtoint(Listbox2.items[0]);
while not tableMain.eof do
begin
if iID = StrToint(tableMain.fieldbyname('ID').value) then
begin
tableMain.Delete;
end;
tableMain.next;
end;
ydCloseDB; //關閉數據庫
end;
// yiShowDB 顯示數據庫的內容在表格中
//1999.9.24. 9.25.
procedure TfrmMain.yiShowDB;
var
i, j: integer;
begin
ydAssignDB('money.dbf');
ydOpenDB; //打開數據庫
listbox1.Items.LoadFromFile(GetAppPath + 'DBTYPE.txt'); //引入數據庫字段文本文件
i := 1;
//循環讀取數據庫內容
while not tableMain.Eof do
begin
for j := 1 to listbox1.items.count do
begin
grid01.Cells[j-1, i] := tableMain.FieldByName(listbox1.items[j - 1]).value
end;
tableMain.Next;
inc(i);
end;
ydCloseDB; //關閉數據庫
end;
//打開數據庫
//1999.9.25.
{ DONE -oyijun : 增加防止出錯的代碼 }
procedure TfrmMain.ydOpenDB;
begin
try
tableMain.Open;
except
gnErr:=100; //打開數據庫出錯
end;
end;
//關閉數據庫
//1999.9.25.
procedure TfrmMain.ydCloseDB;
begin
tableMain.Close;
end;
//修改指定的記錄
//1999.9.25
procedure TfrmMain.ydEditRecord;
begin
//判斷是否選擇了正確的記錄
if grid01.Cells[1, grid01.row] <> '' then begin
gnCurrID := strtoint(grid01.Cells[1, grid01.row]);
//將記錄寫入到ListBox中
listBox2.Clear;
listBox2.Items.Add(grid01.Cells[1, grid01.row]);
listBox2.Items.Add(grid01.Cells[2, grid01.row]);
listBox2.Items.Add(grid01.Cells[3, grid01.row]);
listBox2.Items.Add(grid01.Cells[4, grid01.row]);
listbox2.Items.SaveToFile(GetAppPath + 'rec.txt');
end;
end;
//顯示編輯單條記錄窗口
//1999.9.25.
procedure TfrmMain.yiShowInputWindow(s: string);
var
s1:string;
begin
s1 := ExtractWord(2, s, [' ']);
frmInput.Caption := s1;
frmInput.showmodal;
end;
//在狀態欄顯示信息
//1999.9.25.
procedure TFrmMain.yiShowStatus(s:string);
var
i:integer;
s1:string;
begin
i := StrToInt(ExtractWord(2, s, [' ']));
s1 := ExtractWord(3, s, [' ']);
StatusBar.panels[i].text:=s1;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -