Разработка базы данных
'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.
Размещено на