![]() |
|
|
Дипломная работа: Разработка базы данныхFName:=DataModule1.IBDataSet1.FieldByName('File').AsString; FName:=Concat(OpenDir+FName); OpenFile(FName,OpenDir); end; procedure TMainForm.DataSetFindExecute(Sender: TObject); begin if not Assigned (FindForm) then FindForm:= TFindForm.Create (Application); FindForm.ShowModal; if (DataModule1.fSearchRec>=0) then DatasetFindNext.Enabled:=True else DatasetFindNext.Enabled:=False; end; procedure TMainForm.DataSetFindNextExecute(Sender: TObject); const Txt=’Источник не найден'; WinName='Поиск источника'; var KeyFlds : ShortString; KeyVals : Variant; Loc : TLocateOptions; Res : Boolean; BM : TBookmark; begin BM:=DataModule1.IBDataSet1.GetBookmark; FindForm.GetLocateParams(KeyFlds,KeyVals,Loc); Res:=DataModule1.IBDataSet1.LocateNext(KeyFlds,KeyVals,Loc); with DataModule1 do fSearchRec:=IBDataSet1.RecNo; if not Res then begin DataModule1.IBDataSet1.GotoBookmark(BM); DataModule1.fSearchRec:=-1; DataSetFindNext.Enabled:=False; Application.MessageBox(Txt,WinName,mb_OK); end; DataModule1.IBDataSet1.FreeBookmark(BM); end; procedure TMainForm.DataSetFilterExecute(Sender: TObject); begin if not Assigned (FilterForm) then FilterForm:= TFilterForm.Create(Application); FilterForm.ShowModal; end; procedure TMainForm.DataSetAllExecute(Sender: TObject); begin DataModule1.IBDataSet1.Filtered:=False; end; procedure TMainForm.FileDataBasePathExecute(Sender: TObject); begin if not Assigned (PathForm) then PathForm:= TPathForm.Create(Application); PathForm.ShowModal; DataSetRefrashExecute(Sender); end; procedure TMainForm.FileUserExecute(Sender: TObject); var Path : AnsiString; User : ShortString; Pass : ShortString; begin if not Assigned (UserForm) then UserForm:= TUserForm.Create(Application); with UserForm do begin ShowModal; if ModalResult=mrOK then begin Path:=DataModule1.IBDatabase1.DatabaseName; User:=UserForm.leUser.Text; Pass:=UserForm.lePass.Text; if not DataModule1.Connect(Path,User,Pass) then Close; DataSetRefrashExecute(Sender); DataModule1.SetAccess; DataSetInsert.Enabled:=DataModule1.fWriter; DataSetDelete.Enabled:=DataModule1.fWriter; DataSetUpdate.Enabled:=DataModule1.fWriter; end; end; end; procedure TMainForm.OptColorExecute(Sender: TObject); begin if ColorDialog1.Execute then begin DBGrid1.Color:=ColorDialog1.Color; DBMemo1.Color:=ColorDialog1.Color; Edit1.Color:=ColorDialog1.Color; end; end; procedure TMainForm.OptFontExecute(Sender: TObject); begin if FontDialog1.Execute then begin DBGrid1.Font.Assign(FontDialog1.Font); DBMemo1.Font.Assign(FontDialog1.Font); Edit1.Font.Assign(FontDialog1.Font); end; end; procedure TMainForm.OptConfDelExecute(Sender: TObject); begin ConfirmDelete:=not ConfirmDelete; end; procedure TMainForm.HelpAboutExecute(Sender: TObject); begin if not Assigned (AboutBox) then AboutBox:= TAboutBox.Create (Application); AboutBox.ShowModal; end; end. Приложение Г Листинг модуля DBUnit.pas unit DBUnit; interface uses SysUtils, Classes, DB, IBDatabase, IBCustomDataSet, IBQuery, IBStoredProc; type TDataModule1 = class(TDataModule) DataSource1: TDataSource; IBDatabase1: TIBDatabase; IBTransaction1: TIBTransaction; IBDataSet1: TIBDataSet; IBStoredProc1: TIBStoredProc; function Connect(Path:ANSIString; User, Password: ShortString): Boolean; function InitDBParams: Boolean; procedure SetAccess; procedure CallInsertBook(Aut, Tit, Lan: ShortString; Sec: TStream; Arc: ANSIString; Fil: ShortString; var Num: Integer); procedure CallUpdateBook(Num: Integer; Aut, Tit, Lan: ShortString; Sec: TStream; Arc: ANSIString; Fil: ShortString); procedure CallDeleteBook; procedure SetFilter(CaseFlag: Boolean; Aut, Tit, Lan, Sec: ShortString); function IsFieldContainStr(Field, S: ShortString): Boolean; procedure IBDataSet1FilterRecord(DataSet: TDataSet; var Accept: Boolean); procedure IBDataSet1AfterScroll(DataSet: TDataSet); private fCase : Boolean; fFltrAut: ShortString; fFltrTit: ShortString; fFltrLan: ShortString; fFltrSec: ShortString; public fSearchRec : Integer; fSearchKey : ShortString; fSearchCase: Boolean; fWriter : Boolean; fUser : ShortString; fPass : ShortString; fServer : ShortString; fFile : ShortString; end; var DataModule1: TDataModule1; implementation uses StrUtils, DBTables, Dialogs, Main, Data; {$R *.dfm} { TDataModule1 } function TDataModule1.Connect(Path:ANSIString; User, Password: ShortString): Boolean; const ParamNames: array[0..3] of ShortString = ( 'lc_ctype=', 'sql_role_name=', 'user_name=', 'password='); CharSet='WIN1251'; SQLRole='3'; ErrPathUserPass='Неверный путь к базе или пароль пользователя'; ErrFatal='Соединение с базой данных не возможно'; var OldUser: ShortString; OldPass: ShortString; OldPath: AnsiString; begin OldPath:=''; OldUser:=''; OldPass:=''; with IBDataBase1 do begin IBDataBase1.Connected:=False; if Params.Count<>0 then begin OldUser:=fUser; OldPass:=fPass; OldPath:=DataBaseName; end; IBDataBase1.Params.Clear; Params.Add(Concat(ParamNames[0],CharSet)); Params.Add(Concat(ParamNames[1],SQLRole)); Params.Add(Concat(ParamNames[2],User)); Params.Add(Concat(ParamNames[3],Password)); LoginPrompt:=False; DatabaseName:=Path; end; try IBDataBase1.Connected:=True; fUser:=User; fPass:=Password; except ShowMessage(ErrPathUserPass); if (OldPath<>'') and (OldUser<>'') and (OldPass<>'') then with IBDataBase1 do begin DatabaseName:=OldPath; Params[2]:=OldUser; Params[3]:=OldPass; Connected:=False; try Connected:=True; fUser:=User; fPass:=Password; except ShowMessage(ErrFatal); end; end; end; Result:=IBDataBase1.Connected; end; function TDataModule1.InitDBParams: Boolean; var Path: ANSIString; begin fUser:=ParamStr(1); fPass:=ParamStr(2); fServer:=Paramstr(3); fFile:=Paramstr(4); if (fUser='') then fUser:=DBDefaultUser; if (fPass='') then fPass:=DBDefaultPass; if (fServer='') then fServer:=DBDefaultServer; if (fFile='') then fFile:=DBDefaultFile; Path:=Concat(fServer,':',fFile); Result:=DataModule1.Connect(Path,fUser,fPass); end; procedure TDataModule1.SetAccess; begin with IBStoredProc1 do begin StoredProcName:='IsWriter'; Prepare; try ExecProc; fWriter:=True; except fWriter:=False; end; end; end; procedure TDataModule1.CallInsertBook(Aut, Tit, Lan: ShortString; Sec: TStream; Arc: ANSIString; Fil: ShortString; var Num: Integer); begin with IBStoredProc1 do begin StoredProcName:='InsertBook'; ParamByName('ipAut').Value:=Aut; ParamByName('ipTit').Value:=Tit; ParamByName('ipLan').Value:=Lan; ParamByName('ipSec').LoadFromStream(Sec,ftMemo); ParamByName('ipArc').Value:=Arc; ParamByName('ipFil').Value:=Fil; Prepare; ExecProc; Num:=ParamByName('opNum').Value; end; end; procedure TDataModule1.CallUpdateBook(Num: Integer; Aut, Tit, Lan: ShortString; Sec: TStream; Arc: ANSIString; Fil: ShortString); begin with IBStoredProc1 do begin StoredProcName:='UpdateBook'; ParamByName('ipNum').Value:=Num; ParamByName('ipAut').Value:=Aut; ParamByName('ipTit').Value:=Tit; ParamByName('ipLan').Value:=Lan; ParamByName('ipSec').LoadFromStream(Sec,ftMemo); ParamByName('ipArc').Value:=Arc; ParamByName('ipFil').Value:=Fil; Prepare; ExecProc; end; end; procedure TDataModule1.CallDeleteBook; begin if (IBDataSet1.RecNo<>0) then with IBStoredProc1 do begin StoredProcName:='DeleteBook'; ParamByName('Num').Value:=IBDataSet1.Fields.Fields[0].Value; Prepare; ExecProc; end; end; procedure TDataModule1.SetFilter(CaseFlag: Boolean; Aut, Tit, Lan,Sec: ShortString); begin fCase:=CaseFlag; fFltrAut:=Aut; fFltrTit:=Tit; fFltrLan:=Lan; fFltrSec:=Sec; IBDataSet1.Filtered:=False; IBDataSet1.Filtered:=True; end; function TDataModule1.IsFieldContainStr(Field, S: ShortString): Boolean; begin if Trim(S)<>'' then if fCase then Result:=ANSIContainsStr(Field,S) else Result:=ANSIContainsText(Field,S) else Result:=True; end; procedure TDataModule1.IBDataSet1FilterRecord(DataSet: TDataSet; var Accept: Boolean); var Aut: Boolean; Tit: Boolean; Lan: Boolean; Sec: Boolean; begin Aut:=IsFieldContainStr(DataSet['Author'],fFltrAut); Tit:=IsFieldContainStr(DataSet['Title'],fFltrTit); Lan:=IsFieldContainStr(DataSet['Language'],fFltrLan); Sec:=IsFieldContainStr(DataSet['Sections'],fFltrSec); Accept:=Aut and Tit and Lan and Sec; end; procedure TDataModule1.IBDataSet1AfterScroll(DataSet: TDataSet); var Stream: TStream; begin if not IBDataSet1.FieldByName('Sections').IsNull then begin Stream:=IBDataSet1.CreateBlobStream(IBDataSet1.FieldByName('Sections'),bmRead); Stream.Free; end; end; end. Приложение Д Листинг модуля Edit.pas unit Edit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Buttons, CheckLst, Mask, Menus, ActnList; type TEditForm = class(TForm) Panel1: TPanel; BCancel: TBitBtn; BOK: TBitBtn; Panel2: TPanel; RadioGroupSource: TRadioGroup; OpenDialogArc: TOpenDialog; GroupBoxData: TGroupBox; LabelTit: TLabel; LabelLan: TLabel; LabelTyp: TLabel; LabelAut: TLabel; ComboBoxAut: TComboBox; ComboBoxTit: TComboBox; ComboBoxLan: TComboBox; GroupBoxSections: TGroupBox; GroupBoxPath: TGroupBox; LabelDir: TLabel; EditDir: TEdit; BBrowseDir: TBitBtn; LabelArc: TLabel; EditArc: TEdit; BBrowseArc: TBitBtn; LabelFile: TLabel; EditFile: TEdit; BBrowseFile: TBitBtn; EditNewArc: TEdit; LabelNewArc: TLabel; Memo1: TMemo; procedure FormActivate(Sender: TObject); procedure SetComboBox(FieldNum: Integer; CBox: TComboBox); procedure BBrowseArcClick(Sender: TObject); procedure BBrowseFileClick(Sender: TObject); procedure RadioGroupSourceClick(Sender: TObject); procedure BBrowseDirClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var EditForm: TEditForm; implementation uses DB, DirSource, DBUnit, Files, Data; {$R *.dfm} procedure TEditForm.FormActivate(Sender: TObject); begin SetComboBox(1,ComboBoxAut); SetComboBox(2,ComboBoxTit); SetComboBox(3,ComboBoxLan); RadioGroupSourceClick(Sender); end; procedure TEditForm.SetComboBox(FieldNum: Integer; CBox: TComboBox); var B : TBookmark; S : ShortString; Present: Boolean; I : Integer; begin CBox.Items.Clear; with DataModule1.IBDataSet1 do begin B:=GetBookmark; First; DisableControls; while not EOF do begin S:=Fields.Fields[FieldNum].AsString; if S<>'' then begin Present:=False; for I:=0 to CBox.Items.Count-1 do if S=CBox.Items.Strings[I] then begin Present:=True; Break; end; if (not Present) then CBox.Items.Add(S); end; Next; end; GotoBookmark(B); FreeBookmark(B); EnableControls; end; end; procedure TEditForm.BBrowseArcClick(Sender: TObject); begin with OpenDialogArc do begin Title:='Поиск архива'; Filter := 'Любые архивы|*.RAR;*ZIP;*ARJ'+ 'Любые файлы|*.*'+ 'RAR-архивы (*.rar)|*.RAR|'+ 'ZIP-архивы (*.zip)|*.ZIP|'+ 'ARJ-архивы (*.arj)|*.ARJ'; InitialDir:=InitDir; if Execute then begin EditArc.Text:=FileName; BBrowseFile.Enabled:=True; EditFile.Text:=''; end; end; end; procedure TEditForm.BBrowseFileClick(Sender: TObject); var ArcPath: ANSIString; OpenDir: ANSIString; Res : Boolean; OpenDialogFile: TOpenDialog; begin Res:=True; if RadioGroupSource.ItemIndex = 1 then begin Res:=CopyFiles(EditForm.Handle,EditArc.Text, Root+TmpDir+ExtractFileName(EditArc.Text))=0; if Res then begin ArcPath:=Concat(Root,TmpDir,ExtractFileName(EditArc.Text)); OpenDir:=Concat(Root,BrowseDir); Res:=UnPackFiles(ArcPath,OpenDir); end; end; if Res then begin OpenDialogFile:=TOpenDialog.Create(Application); with OpenDialogFile do begin InitialDir:='E:\Andrew\'; Title:='Главный файл'; Filter := 'Любые документы |'+ '*.TXT;*.DOC;*.RTF;*.WRI;*.PDF;*.HTM;*.HTML;*.SHTML;*.XML|'+ 'Любые файлы (*.*)|*.*|'+ 'Текстовые файлы (*.txt)|*.TXT|'+ 'Докуметы Word(*.doc)|*.DOC|'+ 'Rich Text Format(*.rtf)|*.RTF|'+ 'Текст в формате WRI(*.wri)|*.WRI|'+ 'Документы Acrobat (*.pdf)|*.PDF|'+ 'Web-страницы(*.htm, *.html, *.shtml, *.xml)|*.HTM;*.HTML;*.SHTML;*. case RadioGroupSource.ItemIndex of 0: InitialDir:=DirSourceForm.ShellComboBox1.Path; 1: InitialDir:=Root+BrowseDir; 2: InitialDir:=InitDir; end; if Execute then case RadioGroupSource.ItemIndex of 0: EditFile.Text:=ExtractFileName(FileName); 1: EditFile.Text:=ExtractFileName(FileName); 2: EditFile.Text:=FileName; end; end; OpenDialogFile.Free; end; if RadioGroupSource.ItemIndex = 1 then begin DeleteFiles(EditForm.Handle,Root+BrowseDir+'*.*'); DeleteFiles(EditForm.Handle,Root+TmpDir+ExtractFileName(EditArc.Text)); end; end; procedure TEditForm.RadioGroupSourceClick(Sender: TObject); begin LabelDir.Enabled:=RadioGroupSource.ItemIndex = 0; EditDir.Enabled:=RadioGroupSource.ItemIndex = 0; BBrowseDir.Enabled:=RadioGroupSource.ItemIndex = 0; LabelArc.Enabled:=RadioGroupSource.ItemIndex = 1; EditArc.Enabled:=RadioGroupSource.ItemIndex = 1; BBrowseArc.Enabled:=RadioGroupSource.ItemIndex = 1; end; procedure TEditForm.BBrowseDirClick(Sender: TObject); begin if not Assigned (DirSourceForm) then DirSourceForm:= TDirSourceForm.Create (Application); DirSourceForm.ShowModal; if DirSourceForm.ModalResult = mrOK then EditDir.Text:=DirSourceForm.ShellComboBox1.Path; end; end. Приложение Е Листинг модуля Delete.pas unit Delete; interface uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, Buttons, ExtCtrls; type TDeleteForm = class(TForm) Bevel1: TBevel; Label1: TLabel; BYes: TBitBtn; BNo: TBitBtn; Image1: TImage; private { Private declarations } public { Public declarations } end; var DeleteForm: TDeleteForm; implementation {$R *.dfm} end. Приложение Ж Листинг модуля Filter.pas unit Filter; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls; type TFilterForm = class(TForm) Panel1: TPanel; Panel2: TPanel; GBFilterValue: TGroupBox; EditAut: TEdit; EditTit: TEdit; EditLan: TEdit; LabelAut: TLabel; LabelTit: TLabel; LabelLan: TLabel; BBOK: TBitBtn; BBCancel: TBitBtn; LabelSec: TLabel; EditSec: TEdit; CBCase: TCheckBox; procedure FormDeactivate(Sender: TObject); private { Private declarations } public { Public declarations } end; var FilterForm: TFilterForm; implementation uses DB, DBUnit; {$R *.dfm} procedure TFilterForm.FormDeactivate(Sender: TObject); begin if ModalResult=mrOK then DataModule1.SetFilter(CBCase.Checked, EditAut.Text, EditTit.Text, EditLan.Text, EditSec.Text); end; end. Приложение З Листинг модуля Find.pas unit Find; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, DB; type TFindForm = class(TForm) Panel1: TPanel; BOK: TBitBtn; Panel2: TPanel; gbValue: TGroupBox; LabelAut: TLabel; LabelTit: TLabel; LabelLan: TLabel; LabelSec: TLabel; EditAut: TEdit; EditTit: TEdit; EditLan: TEdit; EditSec: TEdit; BCancel: TBitBtn; EditNum: TEdit; LabelNum: TLabel; gbParam: TGroupBox; CheckBoxCase: TCheckBox; CheckBoxSubStr: TCheckBox; procedure FormDeactivate(Sender: TObject); procedure SetFieldParams(FldNum: Byte; var Fields: ShortString; var Values: Variant); procedure GetLocateParams(var KeyFields: ShortString; var KeyValues: Variant; var Options: TLocateOptions); private { Private declarations } public { Public declarations } end; var FindForm: TFindForm; implementation uses DBUnit, Data; {$R *.dfm} procedure TFindForm.FormDeactivate(Sender: TObject); const Txt='Источник не найден'; WinName='Поиск источника'; var KeyFlds : ShortString; KeyVals : Variant; Loc : TLocateOptions; Res : Boolean; BM : TBookmark; begin if ModalResult=mrOK then begin BM:=DataModule1.IBDataSet1.GetBookmark; GetLocateParams(KeyFlds,KeyVals,Loc); Res:=DataModule1.IBDataSet1.Locate(KeyFlds,KeyVals,Loc); with DataModule1 do fSearchRec:=IBDataSet1.RecNo; if not Res then begin DataModule1.IBDataSet1.GotoBookmark(BM); DataModule1.fSearchRec:=-1; Application.MessageBox(Txt,WinName,mb_OK); end; DataModule1.IBDataSet1.FreeBookmark(BM); end; end; procedure TFindForm.GetLocateParams(var KeyFields: ShortString; var KeyValues: Variant; var Options: TLocateOptions); begin KeyFields:=''; KeyValues:=VarArrayOf([]); SetFieldParams(0,KeyFields,KeyValues); SetFieldParams(1,KeyFields,KeyValues); SetFieldParams(2,KeyFields,KeyValues); SetFieldParams(3,KeyFields,KeyValues); SetFieldParams(4,KeyFields,KeyValues); Options:=[]; if CheckBoxCase.Checked then Options:=Options+[loCaseInsensitive]; if CheckBoxSubStr.Checked then Options:=Options+[loPartialKey]; end; procedure TFindForm.SetFieldParams(FldNum: Byte; var Fields: ShortString; var Values: Variant); var S: ShortString; N: Integer; begin case FldNum of 0: S:=EditNum.Text; 1: S:=EditAut.Text; 2: S:=EditTit.Text; 3: S:=EditLan.Text; 4: S:=EditSec.Text; end; S:=Trim(S); if S<>'' then begin Fields:=Concat(Fields,FieldNames[FldNum],';'); N:=VarArrayHighBound(Values,1)+1; VarArrayRedim(Values,N); if (FldNum = 0) then Values[N]:=StrToInt(S) else Values[N]:=S; end; end; end. Приложение И Листинг модуля DirSource.pas unit DirSource; interface uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, Buttons, ExtCtrls, ComCtrls, ShellCtrls; type TDirSourceForm = class(TForm) Bevel1: TBevel; BCancel: TBitBtn; BOK: TBitBtn; ShellComboBox1: TShellComboBox; ShellTreeView1: TShellTreeView; private { Private declarations } public { Public declarations } end; var DirSourceForm: TDirSourceForm; implementation {$R *.dfm} end. Приложение К Листинг модуля Path.pas unit Path; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Buttons; type TPathForm = class(TForm) Panel1: TPanel; BBOK: TBitBtn; BBCancel: TBitBtn; Panel2: TPanel; leServer: TLabeledEdit; leFile: TLabeledEdit; procedure FormActivate(Sender: TObject); procedure FormDeactivate(Sender: TObject); private { Private declarations } public { Public declarations } end; var PathForm: TPathForm; implementation uses Data, DBUnit; {$R *.dfm} procedure TPathForm.FormActivate(Sender: TObject); begin leServer.Text:=DataModule1.fServer; leFile.Text:=DataModule1.fFile; end; procedure TPathForm.FormDeactivate(Sender: TObject); var Path : AnsiString; User : ShortString; Pass : ShortString; begin if ModalResult=mrOK then begin Path:=Concat(leServer.Text,':',lefile.Text); User:=DataModule1.fUser; Pass:=DataModule1.fPass; if not DataModule1.Connect(Path,User,Pass) then Close; end; end; end. Приложение Л Листинг модуля User.pas unit User; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Buttons; type TUserForm = class(TForm) Panel1: TPanel; BBOK: TBitBtn; BBCancel: TBitBtn; Panel2: TPanel; leUser: TLabeledEdit; lePass: TLabeledEdit; private { Private declarations } public { Public declarations } end; var UserForm: TUserForm; implementation {$R *.dfm} end. Приложение М Листинг модуля About.pas unit About; interface uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, Buttons, ExtCtrls, jpeg; type TAboutBox = class(TForm) Panel1: TPanel; ProgramIcon: TImage; ProductName: TLabel; Version: TLabel; Copyright: TLabel; Comments: TLabel; BitBtnOK: TBitBtn; Date: TLabel; private { Private declarations } public { Public declarations } end; var AboutBox: TAboutBox; implementation {$R *.dfm} end. Приложение Н Листинг модуля Data.pas unit Data; {$WRITEABLECONST ON} interface uses Graphics; const DBDefaultServer: ShortString ='Server-1'; DBDefaultFile: ANSIString ='G:\LibDB\Lib.gdb'; LibDir='\\Server-1\_Literature\__\'; InitDir='\\Server-1\_Literature\'; DBDefaultUser: ShortString ='GUEST'; DBDefaultPass: ShortString ='please'; IniFile='Lib.ini'; TmpDir='Tmp\'; BrowseDir=TmpDir+'Browse\'; TmpFile='Tmp'; ArcExt='.rar'; PathLen =1000; InsertWinName=Добавление нового источника'; EditWinName='Редактирование источника '; DeleteWinName='Удаление источника '; FieldNames: array [0..4] of ShortString=( 'Number', 'Author', 'Title', 'Language', 'Sections'); SQLSortBy : array [0..4] of ShortString=( 'ORDER BY "Number" ', 'ORDER BY "Author" ', 'ORDER BY "Title" ', 'ORDER BY "Language" ', ''); SQLSortDir: array [0..1] of ShortString=( '', 'DESC'); DefaultWinState = 2; DefaultWinTop = 0; DefaultWinBottom = 0; DefaultWinLeft = 400; DefaultWinRight = 600; DefaultMemoTop = 0; DefaultMemoBottom = 0; DefaultMemoLeft = 400; DefaultMemoRight = 600; DefaultGrid0= 36; DefaultGrid1= 117; DefaultGrid2= 279; DefaultGrid3= 52; DefaultGrid4= 150; DefaultGrid5= 122; DefaultColor= clWindow; DefaultFontCharset= 1 ; DefaultFontColor=clWindowText; DefaultFontHeight=-11; DefaultFontName='MS Sans Serif'; DefaultFontPitch=Ord(fpDefault); DefaultFontSize=8; DefaultFontBold=False; DefaultFontItalic=False; DefaultFontUnderLine=False; DefaultFontStrikeOut=False; ConfirmDelete: Boolean = True; var Root : ANSIString; implementation end. Приложение О Листинг модуля Files.pas unit Files; interface uses Windows, SysUtils, Dialogs, IniFiles; function CopyFiles(Handle:HWND; Source, Dest: ANSIString): Longint; procedure DeleteFileExt(var Name:ANSIString); function DeleteFiles(Handle:HWND; Source: ANSIString): Longint; function ExtractFileLastDir(Name: ANSIString): ANSIString; function GetNewArcName(Path: ShortString): ShortString; procedure OpenFile(FileName: TFileName; Dir:ANSIString); function PackFiles(ArcName, Path: ANSIString): Boolean; function RunApp(Title, Name, CmdLn: ANSIString): DWORD; function UnPackFiles(ArcName, Dir: ANSIString): Boolean; implementation uses ShellAPI, Forms, Classes, Data; const NError=3; ErrorMsg: array[1..NError] of ShortString=( 'Упаковка файлов прервана', 'Распаковка временных файлов прервана', 'Файл неоткрывается'); RARName ='Rar.exe'; WinRARName='WinRar'; PackKey='a -ep1'; UnPackKey='x'; RARTitle='Óïàêîâêà ôàéëîâ'; Bl =' '; function CopyFiles(Handle:HWND; Source, Dest: ANSIString): Longint; var F : TSHFileOpStruct; Buffer1: array[0..4096] of Char; Buffer2: array[0..4096] of Char; S : PChar; D : PChar; begin FillChar(Buffer1, SizeOf(Buffer1), #0); FillChar(Buffer2, SizeOf(Buffer2), #0); S := @Buffer1; D := @Buffer2; StrPCopy(S, Source); StrPCopy(D, Dest); FillChar(F, SizeOf(F), #0); F.Wnd := Handle; F.wFunc := FO_COPY; F.pFrom := @Buffer1; F.pTo := @Buffer2; F.fFlags := 0; Result:=SHFileOperation(F); end; procedure DeleteFileExt(var Name:ANSIString); var Ext : ShortString; LenExt : Integer; LenName: Integer; begin Ext:=ExtractFileExt(Name); LenExt:=Length(Ext); LenName:=Length(Name); Delete(Name,LenName-LenExt+1,LenName); end; function DeleteFiles(Handle:HWND; Source: ANSIString): Longint; var F : TSHFileOpStruct; Buffer: array[0..4096] of Char; S : PChar; begin FillChar(Buffer, SizeOf(Buffer), #0); S := @Buffer; StrPCopy(S, Source); FillChar(F, SizeOf(F), #0); F.Wnd := Handle; F.wFunc := FO_DELETE; F.pFrom := @Buffer; F.fFlags := FOF_NOCONFIRMATION; Result:=SHFileOperation(F); end; function ExtractFileLastDir(Name: ANSIString): ANSIString; var I: Integer; L: Integer; begin L:=Length(Name); I:=L+1; repeat Dec(I); until Name[I]='\'; Result:=Copy(Name,I,L-I); end; function GetNewArcName(Path: ShortString): ShortString; var ExtLen : Integer; NameLen: Integer; I : Integer; Ext : ShortString; Dir : ShortString; Name : ShortString; begin Dir:=ExtractFilePath(Path); Name:=ExtractFileName(Path); if Trim(Name)='' then Name:='Arc'; if FileExists(Dir+Name) then begin Ext:=ExtractFileExt(Name); ExtLen:=Length(Ext); NameLen:=Length(Name); Insert('1',Name,NameLen-ExtLen+1); I:=2; while FileExists(Dir+Name) do begin Delete(Name,NameLen-ExtLen+1,Length(Name)); Name:=Concat(Name,IntToStr(I),Ext); Inc(I); end; end; Ext:=ExtractFileExt(Name); if Ext='' then Name:=Concat(Name,ArcExt); Result:=Concat(Dir,Name); end; procedure OpenFile(FileName: TFileName; Dir:ANSIString); var PPath : PChar; POpenDir: PChar; Res : DWORD; begin FileName:=Concat(FileName); GetMem(PPath,PathLen); GetMem(POpenDir,Length(Dir)+1); StrPCopy(POpenDir,Dir); FindExecutable(PChar(FileName),PChar(Dir),PPath); Res:=ShellExecute(Application.Handle,'open',PPath,PChar(FileName), POpenDir,SW_SHOWNORMAL); if Res<32 then ShowMessage(ErrorMsg[3]); FreeMem(POpenDir); FreeMem(PPath); end; function PackFiles(ArcName, Path: ANSIString): Boolean; var Param : ShortString; Res : DWORD; PPath : PChar; F : TFileStream; FName : TFileName; begin FName:=Concat(Root,TmpDir,TmpFile,'1',ArcExt); F:=TFileStream.Create(FName,fmCreate); GetMem(PPath, PathLen); if FindExecutable(PChar(FName),PChar(0),PPath)>32 then begin Param:=Concat(WinRARName,Bl,PackKey,Bl,ArcName,Bl,Path); Res:=RunApp('',PPath,Param); end else begin Res:=0; end; if (Res<>0) then begin DeleteFiles(Application.Handle,ArcName); ShowMessage(ErrorMsg[1]); Result:=False; end else Result:=True; FreeMem(PPath); F.Free; DeleteFiles(Application.Handle,FName); end; function RunApp(Title, Name, CmdLn: ANSIString):DWORD; var Startup: TStartupInfo; Process: TProcessInformation; Status : DWORD; Env : Pointer; begin ChDir(Root); New(Env); Startup.lpReserved := PChar(0); Startup.lpDesktop := PChar(0); Startup.lpTitle := PChar(Title); Startup.dwFlags := STARTF_USESHOWWINDOW; Startup.wShowWindow := SW_SHOWNORMAL; Startup.cbReserved2 := 0; Startup.lpReserved2 := PByte(0); if CreateProcess( PChar(Name), // lpApplicationName PChar(CmdLn), // lpCommandLine PSecurityAttributes(0), // lpProcessAttributes PSecurityAttributes(0), // lpThreadAttributes False, // bInheritHandles NORMAL_PRIORITY_CLASS, // dwCreationFlags Env, // lpEnvironment PChar(0), // lpCurrentDirectory Startup, // lpStartupInfo Process // lpProcessInformation )then begin GetExitCodeProcess(Process.hProcess, Status); while Status = STILL_ACTIVE do begin Sleep(10); GetExitCodeProcess(Process.hProcess, Status); end; end; Dispose(Env); Result:=Status; end; function UnPackFiles(ArcName, Dir: ANSIString): Boolean; var PPath : PChar; Param : ShortString; Res : DWORD; begin ArcName:=Concat('"',ArcName,'"'); GetMem(PPath, PathLen); if FindExecutable(PChar(ArcName),PChar(0),PPath)>32 then begin Param:=Concat(WinRARName,Bl,UnPackKey,Bl,ArcName,Bl,Dir); Res:=RunApp('',PPath,Param); end else begin Res:=0; end; FreeMem(PPath); if Res<>0 then begin DeleteFiles(Application.Handle,Dir+'*.*'); ShowMessage(ErrorMsg[2]); Result:=False; end else Result:=True; end; end. |
Страницы: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
![]() |
||
НОВОСТИ | ![]() |
![]() |
||
ВХОД | ![]() |
|
Рефераты бесплатно, реферат бесплатно, рефераты на тему, сочинения, курсовые работы, реферат, доклады, рефераты, рефераты скачать, курсовые, дипломы, научные работы и многое другое. |
||
При использовании материалов - ссылка на сайт обязательна. |