mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-06 21:47:58 +02:00

http://peter@svn.freepascal.org/svn/fpc/trunk ........ r2556 | marco | 2006-02-12 23:00:38 +0100 (Sun, 12 Feb 2006) | 2 lines * dbf_wtil reenabled for x86_64 ........ r2557 | peter | 2006-02-13 08:19:07 +0100 (Mon, 13 Feb 2006) | 2 lines * remove duplicate dbf_wtil ........ r2558 | peter | 2006-02-13 10:15:11 +0100 (Mon, 13 Feb 2006) | 3 lines * make solaris zipinstall working * remove ezcgi.inc, use GetEnvironmentVariable from SysUtils ........ r2604 | joost | 2006-02-16 00:24:09 +0100 (Thu, 16 Feb 2006) | 1 line + implemented TOracleConnection ........ r2630 | joost | 2006-02-19 16:08:00 +0100 (Sun, 19 Feb 2006) | 1 line + Do not handle :: in a query as a parameter (bug 4813-2) ........ r2631 | joost | 2006-02-19 16:22:21 +0100 (Sun, 19 Feb 2006) | 3 lines + added empty TSQLConnection.GetHandle + added empty TSQLConnection.CreateBlobStream + implemented TSQLConnection.StartTransaction and EndTransaction ........ r2635 | joost | 2006-02-19 18:42:26 +0100 (Sun, 19 Feb 2006) | 1 line + fixed an enabled oracle for win32 ........ r2638 | florian | 2006-02-19 22:33:59 +0100 (Sun, 19 Feb 2006) | 2 lines * ar patch from Yury ........ r2640 | peter | 2006-02-20 07:59:14 +0100 (Mon, 20 Feb 2006) | 2 lines * fix range error ........ r2649 | jonas | 2006-02-20 11:39:37 +0100 (Mon, 20 Feb 2006) | 2 lines * fixed range errors ........ r2657 | joost | 2006-02-20 17:53:35 +0100 (Mon, 20 Feb 2006) | 1 line + Fixed mysql_error ........ r2660 | joost | 2006-02-21 11:14:31 +0100 (Tue, 21 Feb 2006) | 1 line + Moved obsolete DB-units to unmaintained ........ r2661 | joost | 2006-02-21 11:17:47 +0100 (Tue, 21 Feb 2006) | 1 line + renamed tests to ddg ........ r2662 | joost | 2006-02-21 15:29:30 +0100 (Tue, 21 Feb 2006) | 1 line * Fix for error-handling when a TSQLQuery is opened. ........ r2663 | joost | 2006-02-21 22:17:11 +0100 (Tue, 21 Feb 2006) | 4 lines + made TDataset.CreateFields virtual (delphi compat) + implemented TParam.AsLargeInt + cleanup of IBConnection LargeInt code + implemented LargeInt parameter type for IBConnection ........ r2664 | joost | 2006-02-22 12:58:35 +0100 (Wed, 22 Feb 2006) | 1 line + forgot to include changes in db.pp and dsparams.inc in r2663 ........ r2678 | daniel | 2006-02-25 00:31:55 +0100 (Sat, 25 Feb 2006) | 2 lines * Optimize keyboard unit for code size; now 3kb+ object code less. ........ r2706 | hajny | 2006-02-28 00:43:30 +0100 (Tue, 28 Feb 2006) | 1 line * attempt to fix broken compilation for go32v2 target ........ r2719 | daniel | 2006-03-01 13:54:26 +0100 (Wed, 01 Mar 2006) | 2 lines * Convert to table to reduce exe size. ........ r2720 | daniel | 2006-03-01 16:29:05 +0100 (Wed, 01 Mar 2006) | 3 lines - Remove usage of memory unit; things like the lowmemory function are flawed for the same reason memavail is flawed. ........ r2724 | jonas | 2006-03-03 20:29:07 +0100 (Fri, 03 Mar 2006) | 3 lines + added extra info about when parser_e_illegal_assignment_to_count_var can happen ........ r2746 | hajny | 2006-03-05 00:05:24 +0100 (Sun, 05 Mar 2006) | 1 line * Fix to allow / instead of " fexpand.inc ........ r2747 | hajny | 2006-03-05 00:09:06 +0100 (Sun, 05 Mar 2006) | 1 line * Slight optimization (constant instead of variable in assignment) ........ r2748 | tom_at_work | 2006-03-05 00:40:43 +0100 (Sun, 05 Mar 2006) | 2 lines * changed library handle types to the correct TLibHandle * avoid call of FreeLibrary() with zero, because it crashes on some linux versions ........ r2749 | tom_at_work | 2006-03-05 10:18:36 +0100 (Sun, 05 Mar 2006) | 1 line * fixed opengl package compilation on Win32 ........ r2750 | yury | 2006-03-05 10:48:31 +0100 (Sun, 05 Mar 2006) | 1 line * fixed paszlib compiling in objfpc/delphi mode. ........ r2759 | marco | 2006-03-05 14:36:31 +0100 (Sun, 05 Mar 2006) | 3 lines * now first searches ppcross<target> if -P<target> is specified. After that it still searches for ppc<target> ........ r2761 | daniel | 2006-03-05 19:27:17 +0100 (Sun, 05 Mar 2006) | 2 lines * Add extra sequences for FreeBSD xterm ........ r2767 | peter | 2006-03-05 21:16:03 +0100 (Sun, 05 Mar 2006) | 2 lines * fixed xmlreg depends ........ r2768 | yury | 2006-03-05 21:36:16 +0100 (Sun, 05 Mar 2006) | 2 lines * do not try to call cross compiler if host CPU was specified using -P parameter. * tabs to spaces. ........ r2776 | peter | 2006-03-05 22:53:41 +0100 (Sun, 05 Mar 2006) | 2 lines * fixed invalid typecast ........ r2777 | daniel | 2006-03-05 23:00:20 +0100 (Sun, 05 Mar 2006) | 2 lines * Send escape code to xterm to make alt+key send an escape prefix. ........ r2787 | peter | 2006-03-06 12:25:09 +0100 (Mon, 06 Mar 2006) | 2 lines * fix for bug #4962, fix by Marton Pap ........ git-svn-id: branches/fixes_2_0@2797 -
740 lines
24 KiB
ObjectPascal
740 lines
24 KiB
ObjectPascal
{ Resource Unit
|
|
|
|
Programmer: Brad Williams
|
|
BitSoft Development, L.L.C.
|
|
Copyright (c) 1996
|
|
Version 1.1
|
|
|
|
Revision History
|
|
|
|
1.1 (12/26/97)
|
|
- updated to add cdResource directive so that can use standard TStringList
|
|
resources created by TVRW and TVDT
|
|
|
|
1.0
|
|
- original implementation }
|
|
|
|
unit Resource;
|
|
|
|
interface
|
|
|
|
{
|
|
The Resource unit provides global variables which are used to build and
|
|
access resource files. InitRez must always be called before accessing any
|
|
variables in the Resource unit. The programmer should also always call
|
|
Done to free all file handles allocated to the program.
|
|
}
|
|
|
|
{$i platform.inc}
|
|
|
|
{$ifdef PPC_FPC}
|
|
{$H-}
|
|
{$else}
|
|
{$F+,O+,E+,N+}
|
|
{$endif}
|
|
{$X+,R-,I-,Q-,V-}
|
|
{$ifndef OS_UNIX}
|
|
{$S-}
|
|
{$endif}
|
|
|
|
uses
|
|
|
|
FVConsts, Objects, Dos;
|
|
|
|
const
|
|
|
|
RezExt: ExtStr = '.RES';
|
|
{ The file extension used on all resource files. }
|
|
RezBufferSize: Word = 4096;
|
|
{ RezBufferSize is the number of bytes to use for the resource file's
|
|
stream's buffer. RezBufferSize is passed to TBufStream.Init. }
|
|
|
|
{ reXXXX constants are used with resource files to retrieve the standard
|
|
Free Vision dialogs. The constant is followed by the Unit in which it
|
|
is used and the resource which is stored separated by a period. }
|
|
|
|
reChDirDialog = 'ChDirDialog'; { StdDlg.TChDirDialog }
|
|
reEditChDirDialog = 'EditChDirDialog'; { StdDlg.TEditChDirDialog }
|
|
reFindTextDlg = 'FindTextDlg'; { Editors.CreateFindDialog }
|
|
reHints = 'Hints'; { Resource.Hints }
|
|
reJumpLineDlg = 'JumpLineDlg'; { Editors.MakeJumpLineDlg }
|
|
reLabels = 'Labels'; { Resource.Labels }
|
|
reMenuBar = 'MenuBar'; { App.MenuBar }
|
|
reOpenDlg = 'OpenDlg'; { StdDlg.TFileDialog - Open }
|
|
reReformDocDlg = 'ReformDocDlg'; { Editors.MakeReformDocDlg }
|
|
reReplaceDlg = 'ReplaceDlg'; { Editors.CreateReplaceDialog }
|
|
reRightMarginDlg = 'RightMarginDlg'; { Editors.MakeRightMarginDlg }
|
|
reStatusLine = 'StatusLine'; { App.StatusLine }
|
|
reStrings = 'Strings'; { Resource.Strings }
|
|
reSaveAsDlg = 'SaveAsDlg'; { StdDlg.TFileDialog - Save As }
|
|
reTabStopDlg = 'TabStopDlg'; { Editors.MakeTabStopDlg }
|
|
reWindowListDlg = 'WindowListDlg'; { Editors.MakeWindowListDlg }
|
|
reAboutDlg = 'About'; { App unit about dialog }
|
|
|
|
{$I str.inc}
|
|
{ STR.INC declares all the string list constants used in the standard
|
|
Free Vision library units. They are placed in a separate file as a
|
|
template for use by the resource file generator, MakeRez.
|
|
|
|
Applications which use resource files and need to add strings of their
|
|
own should use STR.INC as the start for the resource file.
|
|
|
|
See MakeRez.PAS for more information about generating resource files.}
|
|
|
|
type
|
|
|
|
|
|
PConstant = ^TConstant;
|
|
TConstant = object(TObject)
|
|
Value: Word;
|
|
{ The value assigned to the constant. }
|
|
constructor Init (AValue: Word; AText: string);
|
|
{ Init assigns AValue to Value to AText to Text. AText may be an empty
|
|
string.
|
|
|
|
If an error occurs Init fails. }
|
|
destructor Done; virtual;
|
|
{ Done disposes of Text then calls the inherited destructor. }
|
|
procedure SetText (AText: string);
|
|
{ SetText changes FText to the word equivalent of AText. }
|
|
procedure SetValue (AValue: string);
|
|
{ SetValue changes Value to the word equivalent of AValue. }
|
|
function Text: string;
|
|
{ Text returns a string equivalent to FText. If FText is nil, an
|
|
empty string is returned. }
|
|
function ValueAsString: string;
|
|
{ ValueAsString returns the string equivalent of Value. }
|
|
private
|
|
FText: PString;
|
|
{ The text to display for the constant. }
|
|
end; { of TConstant }
|
|
|
|
|
|
PMemStringList = ^TMemStringList;
|
|
TMemStringList = object(TSortedCollection)
|
|
{ A TMemStringList combines the functions of a TStrListMaker and a
|
|
TStringList into one object, allowing generation and use of string
|
|
lists in the same application. TMemStringList is fully compatible
|
|
with string lists created using TStrListMaker, so legacy applications
|
|
will work without problems.
|
|
|
|
When using a string list in the same program as it is created, a
|
|
resource file is not required. This allows language independant coding
|
|
of units without the need for conditional defines and recompiling. }
|
|
constructor Init;
|
|
{ Creates an empty, in-memory string list that is not associated with a
|
|
resource file. }
|
|
constructor Load (var S: TStream);
|
|
{ Load creates a TStringList from which it gets its strings upon a call
|
|
to Get. The strings on the resource file may be loaded into memory
|
|
for editing by calling LoadList.
|
|
|
|
If initialized with Load, the stream must remain valid for the life
|
|
of this object. }
|
|
destructor Done; virtual;
|
|
{ Done deallocates the memory allocated to the string list. }
|
|
function Compare (Key1, Key2: Pointer): Sw_Integer; virtual;
|
|
{ Compare assumes Key1 and Key2 are Word values and returns:
|
|
|
|
-1 if Key1 < Key2
|
|
0 if Key1 = Key2
|
|
1 if Key1 > Key2 }
|
|
function Get (Key: Word): String; virtual;
|
|
{ GetKey searches for a string with a key matching Key and returns it.
|
|
An empty string is returned if a string with a matching Key is not
|
|
found.
|
|
|
|
If Count > 0, the in memory collection is searched. If List^.Count
|
|
is 0, the inherited Get method is called. }
|
|
procedure Insert (Item: Pointer); virtual;
|
|
{ If Item is not nil, Insert attempts to insert the item into the
|
|
collection. If a collection expansion error occurs Insert disposes
|
|
of Item by calling FreeItem.
|
|
|
|
Item must be a pointer to a TConstant or its descendant. }
|
|
function KeyOf (Item: Pointer): Pointer; virtual;
|
|
{ KeyOf returns a pointer to TConstant.Value. }
|
|
function LoadStrings: Sw_Integer;
|
|
{ LoadStrings reads all strings the associated resource file into
|
|
memory, places them in the collection, and returns 0.
|
|
|
|
If an error occurs LoadStrings returns the stream status error code
|
|
or a DOS error code. Possible DOS error codes include:
|
|
|
|
2: no associated resource file
|
|
8: out of memory }
|
|
function NewConstant (Value: Word; S: string): PConstant; virtual;
|
|
{ NewConstant is called by LoadStrings. }
|
|
procedure Put (Key: Word; S: String); virtual;
|
|
{ Put creates a new PConstant containing Key and Word then calls
|
|
Insert to place it in the collection. }
|
|
procedure Store (var S: TStream);
|
|
{ Store creates a TStrListMaker, fills it with the items in List,
|
|
writes the TStrListMaker to the stream by calling
|
|
TStrListMaker.Store, then disposes of the TStrListMaker. }
|
|
private
|
|
StringList: PStringList;
|
|
end; { of TMemStringList) }
|
|
|
|
|
|
var
|
|
|
|
{$ifdef cdResource}
|
|
Hints: PStringList;
|
|
{$else}
|
|
Hints: PMemStringList;
|
|
{$endif cdResource}
|
|
{ Hints is a string list for use within the application to provide
|
|
context sensitive help on the command line. Hints is always used in
|
|
the application. }
|
|
|
|
{$ifdef cdResource}
|
|
Strings: PStringList;
|
|
{$else}
|
|
Strings: PMemStringList;
|
|
{$endif cdResource}
|
|
{ Strings holds messages such as errors and general information that are
|
|
displayed at run-time, normally with MessageBox. Strings is always
|
|
used in the application. }
|
|
|
|
{$ifdef cdResource}
|
|
Labels: PStringList;
|
|
{$else}
|
|
Labels: PMemStringList;
|
|
{$endif cdResource}
|
|
{ Labels is a string list for use within the application when a
|
|
resource file is not used, or when creating a resource file. Labels
|
|
contains all text used in dialog titles, labels, buttons, menus,
|
|
statuslines, etc., used in the application which can be burned into
|
|
language specific resources. It does not contain any messages
|
|
displayed at run-time using MessageBox or the status line hints.
|
|
|
|
Using the Labels variable when creating views allows language
|
|
independant coding of views such as the MessageBox, StdDlg and Editors
|
|
units. }
|
|
|
|
RezFile: PResourceFile;
|
|
{ RezFile is a global variable used when the Free Vision library
|
|
is compiled using the cdResource conditional define, or when creating
|
|
resource files.
|
|
|
|
All standard Free Vision application resources are accessed from the
|
|
resource file using the reXXXX constants. Modify the STR.INC under a
|
|
new file name to create new language specific resource files. See the
|
|
MakeRez program file for more information. }
|
|
|
|
|
|
|
|
procedure DoneResource;
|
|
{ Done destructs all objects initialized in this unit and frees all
|
|
allocated heap. }
|
|
|
|
{$ifndef cdResource}
|
|
function InitResource: Boolean;
|
|
{$endif cdResource}
|
|
{ Init initializes the Hints and Strings for use with in memory strings
|
|
lists. Init should be used in applications which do not use a resource
|
|
file, or when creating resource files. }
|
|
|
|
{$ifdef cdResource}
|
|
function InitRezFile (AFile: FNameStr; Mode: Word;
|
|
var AResFile: PResourceFile): Sw_Integer;
|
|
{$endif cdResource}
|
|
{ InitRezFile initializes a new PResourceFile using the name passed in
|
|
AFile and the stream mode passed in Mode and returns 0.
|
|
|
|
If an error occurs InitRezFile returns the DOS error and AResFile is
|
|
invalid. Possible DOS error values include:
|
|
|
|
2: file not found or other stream initialization error
|
|
11: invalid format - not a valid resource file }
|
|
|
|
{$ifdef cdResource}
|
|
function LoadResource (AFile: FNameStr): Boolean;
|
|
{$endif cdResource}
|
|
{ Load is used to open a resource file for use in the application.
|
|
|
|
For Load to return True, the resource file must be properly opened and
|
|
assigned to RezFile and the Hints string list must be successfully loaded
|
|
from the stream. If an error occurs, Load displays an English error
|
|
message using PrintStr and returns False. }
|
|
|
|
function MergeLists (Source, Dest: PMemStringList): Sw_Integer;
|
|
{ MergeLists moves all key/string pairs from Source to destination,
|
|
deleting them from Source. Duplicate strings are ignored. }
|
|
|
|
|
|
const
|
|
RMemStringList: TStreamRec = (
|
|
ObjType: idMemStringList;
|
|
VmtLink: Ofs(TypeOf(TMemStringList)^);
|
|
Load: @TMemStringList.Load;
|
|
Store: @TMemStringList.Store);
|
|
|
|
|
|
implementation
|
|
|
|
{****************************************************************************}
|
|
{ Private Declarations }
|
|
{****************************************************************************}
|
|
|
|
uses
|
|
{Memory, }Drivers;
|
|
|
|
{****************************************************************************}
|
|
{ TConstant object }
|
|
{****************************************************************************}
|
|
{****************************************************************************}
|
|
{ TConstant.Init }
|
|
{****************************************************************************}
|
|
constructor TConstant.Init (AValue: Word; AText: string);
|
|
begin
|
|
if not inherited Init then
|
|
Fail;
|
|
Value := AValue;
|
|
FText := NewStr(AText);
|
|
if (FText = nil) and (AText <> '') then
|
|
begin
|
|
inherited Done;
|
|
Fail;
|
|
end;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TConstant.Done }
|
|
{****************************************************************************}
|
|
destructor TConstant.Done;
|
|
begin
|
|
DisposeStr(FText);
|
|
inherited Done;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TConstant.SetText }
|
|
{****************************************************************************}
|
|
procedure TConstant.SetText (AText: string);
|
|
begin
|
|
DisposeStr(FText);
|
|
FText := NewStr(AText);
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TConstant.SetValue }
|
|
{****************************************************************************}
|
|
procedure TConstant.SetValue (AValue: string);
|
|
var
|
|
N: Word;
|
|
ErrorCode: Integer;
|
|
begin
|
|
Val(AValue,N,ErrorCode);
|
|
if ErrorCode = 0 then
|
|
Value := N;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TConstant.Text }
|
|
{****************************************************************************}
|
|
function TConstant.Text: string;
|
|
begin
|
|
if (FText = nil) then
|
|
Text := ''
|
|
else Text := FText^;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TConstant.ValueAsString }
|
|
{****************************************************************************}
|
|
function TConstant.ValueAsString: string;
|
|
var
|
|
S: string[5];
|
|
begin
|
|
Str(Value,S);
|
|
ValueAsString := S;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList Object }
|
|
{****************************************************************************}
|
|
{****************************************************************************}
|
|
{ TMemStringList.Init }
|
|
{****************************************************************************}
|
|
constructor TMemStringList.Init;
|
|
begin
|
|
if not inherited Init(10,10) then
|
|
Fail;
|
|
StringList := nil;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.Load }
|
|
{****************************************************************************}
|
|
constructor TMemStringList.Load (var S: TStream);
|
|
begin
|
|
if not inherited Init(10,10) then
|
|
Fail;
|
|
StringList := New(PStringList,Load(S));
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.Done }
|
|
{****************************************************************************}
|
|
destructor TMemStringList.Done;
|
|
begin
|
|
if (StringList <> nil) then
|
|
Dispose(StringList,Done);
|
|
inherited Done;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.Compare }
|
|
{****************************************************************************}
|
|
function TMemStringList.Compare (Key1, Key2: Pointer): Sw_Integer;
|
|
begin
|
|
if Word(Key1^) < Word(Key2^) then
|
|
Compare := -1
|
|
else Compare := Byte(Word(Key1^) > Word(Key2^));
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.Get }
|
|
{****************************************************************************}
|
|
function TMemStringList.Get (Key: Word): string;
|
|
var
|
|
i: Sw_Integer;
|
|
S: string;
|
|
begin
|
|
if (StringList = nil) then
|
|
begin { started with Init, use in memory string list }
|
|
if Search(@Key,i) then
|
|
Get := PConstant(At(i))^.Text
|
|
else Get := '';
|
|
end
|
|
else begin
|
|
S := StringList^.Get(Key);
|
|
Get := S;
|
|
end;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.Insert }
|
|
{****************************************************************************}
|
|
procedure TMemStringList.Insert (Item: Pointer);
|
|
var
|
|
i: Sw_Integer;
|
|
begin
|
|
if (Item <> nil) then
|
|
begin
|
|
i := Count;
|
|
inherited Insert(Item);
|
|
if (i = Count) then { collection expansion failed }
|
|
Dispose(PConstant(Item),Done);
|
|
end;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.KeyOf }
|
|
{****************************************************************************}
|
|
function TMemStringList.KeyOf (Item: Pointer): Pointer;
|
|
begin
|
|
KeyOf := @(PConstant(Item)^.Value);
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.LoadStrings }
|
|
{****************************************************************************}
|
|
function TMemStringList.LoadStrings: Sw_Integer;
|
|
procedure MakeEditableString (var Str: string);
|
|
const
|
|
SpecialChars: array[1..3] of Char = #3#10#13;
|
|
var
|
|
i, j: Byte;
|
|
begin
|
|
for i := 1 to 3 do
|
|
while (Pos(SpecialChars[i],Str) <> 0) do
|
|
begin
|
|
j := Pos(SpecialChars[i],Str);
|
|
System.Delete(Str,j,1);
|
|
case i of
|
|
1: System.Insert('#3',Str,j);
|
|
2: System.Insert('#10',Str,j);
|
|
3: System.Insert('#13',Str,j);
|
|
end;
|
|
end;
|
|
end;
|
|
var
|
|
Constant: PConstant;
|
|
i: Word;
|
|
S: string;
|
|
begin
|
|
LoadStrings := 0;
|
|
if (StringList = nil) then
|
|
begin
|
|
LoadStrings := 2;
|
|
Exit;
|
|
end;
|
|
for i := 0 to 65535 do
|
|
begin
|
|
S := StringList^.Get(i);
|
|
if (S <> '') then
|
|
begin
|
|
MakeEditableString(S);
|
|
Constant := NewConstant(i,S);
|
|
(*
|
|
if LowMemory then
|
|
begin
|
|
if (Constant <> nil) then
|
|
Dispose(Constant,Done);
|
|
LoadStrings := 8; { out of memory }
|
|
Exit;
|
|
end;
|
|
*)
|
|
Insert(Constant);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.NewConstant }
|
|
{****************************************************************************}
|
|
function TMemStringList.NewConstant (Value: Word; S: string): PConstant;
|
|
begin
|
|
NewConstant := New(PConstant,Init(Value,S));
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.Put }
|
|
{****************************************************************************}
|
|
procedure TMemStringList.Put (Key: Word; S: string);
|
|
begin
|
|
Insert(New(PConstant,Init(Key,S)));
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ TMemStringList.Store }
|
|
{****************************************************************************}
|
|
procedure TMemStringList.Store (var S: TStream);
|
|
var
|
|
StrList: PStrListMaker;
|
|
Size: Word;
|
|
procedure Total (Constant: PConstant);{$ifndef FPC}far;{$endif}
|
|
begin
|
|
with Constant^ do
|
|
Inc(Size,Succ(Length(Text)));
|
|
end;
|
|
procedure AddString (Constant: PConstant);{$ifndef FPC}far;{$endif}
|
|
const
|
|
Numbers = ['0'..'9'];
|
|
var
|
|
i, j: Byte;
|
|
N: Byte;
|
|
ErrorCode: Integer;
|
|
S: string;
|
|
begin
|
|
with Constant^ do
|
|
begin
|
|
{ convert formatting characters }
|
|
S := Text;
|
|
while (Pos('#',S) <> 0) do
|
|
begin
|
|
i := Succ(Pos('#',S));
|
|
j := i;
|
|
if (Length(S) > j) then
|
|
Inc(j,Byte(S[Succ(j)] in Numbers));
|
|
Val(Copy(S,i,j-i+1),N,ErrorCode);
|
|
System.Delete(S,Pred(i),j-i+2);
|
|
System.Insert(Char(N),S,Pred(i));
|
|
end;
|
|
StrList^.Put(Value,Text)
|
|
end;
|
|
end;
|
|
begin
|
|
Size := 0;
|
|
ForEach(@Total);
|
|
StrList := New(PStrListMaker,Init(Size,Count * 6));
|
|
if (StrList = nil) then
|
|
begin
|
|
S.Status := 8; { DOS error not enough memory }
|
|
Exit;
|
|
end;
|
|
ForEach(@AddString);
|
|
StrList^.Store(S);
|
|
Dispose(StrList,Done);
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ Public Procedures and Functions }
|
|
{****************************************************************************}
|
|
|
|
{****************************************************************************}
|
|
{ Done }
|
|
{****************************************************************************}
|
|
procedure DoneResource;
|
|
begin
|
|
if (RezFile <> nil) then
|
|
begin
|
|
Dispose(RezFile,Done);
|
|
RezFile:=nil;
|
|
end;
|
|
if (Strings <> nil) then
|
|
begin
|
|
Dispose(Strings,Done);
|
|
Strings:=nil;
|
|
end;
|
|
if (Hints <> nil) then
|
|
begin
|
|
Dispose(Hints,Done);
|
|
Hints:=nil;
|
|
end;
|
|
if (Labels <> nil) then
|
|
begin
|
|
Dispose(Labels,Done);
|
|
Labels:=nil;
|
|
end;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ Init }
|
|
{****************************************************************************}
|
|
{$ifndef cdResource}
|
|
|
|
{$I strtxt.inc}
|
|
{ strtxt.inc contains the real strings and procedures InitRes... which
|
|
is converted from str.inc }
|
|
|
|
function InitResource: Boolean;
|
|
begin
|
|
InitResource := False;
|
|
Hints := New(PMemStringList,Init);
|
|
if (Hints = nil) then
|
|
begin
|
|
PrintStr('Fatal error. Could not create Hints list.');
|
|
Exit;
|
|
end;
|
|
Strings := New(PMemStringList,Init);
|
|
if (Strings = nil) then
|
|
begin
|
|
DoneResource;
|
|
Exit;
|
|
end;
|
|
Labels := New(PMemStringList,Init);
|
|
if (Labels = nil) then
|
|
begin
|
|
DoneResource;
|
|
Exit;
|
|
end;
|
|
{ now load the defaults }
|
|
InitResLabels;
|
|
InitResStrings;
|
|
InitResource := True;
|
|
end;
|
|
{$endif cdResource}
|
|
|
|
{****************************************************************************}
|
|
{ InitRezFile }
|
|
{****************************************************************************}
|
|
{$ifdef cdResource}
|
|
function InitRezFile (AFile: FNameStr; Mode: Word;
|
|
var AResFile: PResourceFile): Sw_Integer;
|
|
var
|
|
Stream: PBufStream;
|
|
Result: Sw_Integer;
|
|
begin
|
|
Stream := New(PBufStream,Init(AFile,Mode,RezBufferSize));
|
|
if (Stream = nil) then
|
|
Result := 2 { file not found; could also be out of memory }
|
|
else begin
|
|
AResFile := New(PResourceFile,Init(Stream));
|
|
if (AResFile = nil) then
|
|
begin
|
|
Dispose(Stream,Done);
|
|
Result := 11;
|
|
end
|
|
else Result := 0;
|
|
end;
|
|
InitRezFile := Result;
|
|
end;
|
|
{$endif cdResource}
|
|
|
|
{****************************************************************************}
|
|
{ Load }
|
|
{****************************************************************************}
|
|
{$ifdef cdResource}
|
|
function LoadResource (AFile: FNameStr): Boolean;
|
|
var
|
|
Stream: PBufStream;
|
|
begin
|
|
Load := False;
|
|
Stream := New(PBufStream,Init(AFile,stOpenRead,RezBufferSize));
|
|
if (Stream = nil) or (Stream^.Status <> 0) then
|
|
begin
|
|
Done;
|
|
PrintStr('Fatal error. Could not open resource file: ' + AFile);
|
|
Exit;
|
|
end;
|
|
RezFile := New(PResourceFile,Init(Stream));
|
|
if (RezFile = nil) then
|
|
begin
|
|
Dispose(Stream,Done);
|
|
Done;
|
|
PrintStr('Fatal error. Could not initialize resource file.');
|
|
Exit;
|
|
end;
|
|
Hints := PStringList(RezFile^.Get(reHints));
|
|
if (Hints = nil) then
|
|
begin
|
|
Done;
|
|
PrintStr('Fatal error. Could not load Hints string list.');
|
|
Exit;
|
|
end;
|
|
Strings := PStringList(RezFile^.Get(reStrings));
|
|
if (Strings = nil) then
|
|
begin
|
|
Done;
|
|
PrintStr('Fatal error. Could not load Strings string list.');
|
|
Exit;
|
|
end;
|
|
Load := True;
|
|
end;
|
|
{$endif cdResource}
|
|
|
|
{****************************************************************************}
|
|
{ MergeLists }
|
|
{****************************************************************************}
|
|
function MergeLists (Source, Dest: PMemStringList): Sw_Integer;
|
|
var
|
|
Result: Sw_Integer;
|
|
procedure MoveItem (Constant: PConstant);{$ifndef FPC}far;{$endif}
|
|
var
|
|
j: Sw_Integer;
|
|
begin
|
|
if (Result = 0) and (not Dest^.Search(Dest^.KeyOf(Constant),j)) then
|
|
begin
|
|
j := Dest^.Count;
|
|
Dest^.Insert(Constant);
|
|
if (j = Dest^.Count) then
|
|
Result := 8
|
|
else Source^.Delete(Constant);
|
|
end;
|
|
end;
|
|
begin
|
|
if (Source = nil) or (Dest = nil) then
|
|
begin
|
|
MergeLists := 6;
|
|
Exit;
|
|
end;
|
|
Result := 0;
|
|
Source^.ForEach(@MoveItem);
|
|
MergeLists := Result;
|
|
end;
|
|
|
|
{****************************************************************************}
|
|
{ Unit Initialization }
|
|
{****************************************************************************}
|
|
|
|
begin
|
|
RezFile := nil;
|
|
Hints := nil;
|
|
Strings := nil;
|
|
Labels := nil;
|
|
end.
|