home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / zkuste / delphi / kompon / d56 / LNGSUPP.ZIP / LangINISupport / MsgINISupp.pas < prev   
Pascal/Delphi Source File  |  2001-12-14  |  3KB  |  127 lines

  1. unit MsgINISupp;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  7.   IniFiles, Dialogs, LngINISupp;
  8.  
  9. type
  10.   TMsgINISupp = class(TComponent)
  11.   private
  12.     FFileName: TFileName;
  13.     FLngINISupp: TLngINISupp;
  14.     procedure SetFileName(const Value: TFileName);
  15.     procedure SetLngINISupp(const Value: TLngINISupp);
  16.     procedure CheckFile(FN: TFileName);
  17.   protected
  18.   public
  19.     procedure Open;
  20.     procedure Close;
  21.     function GetMsg(MsgName: String):String;
  22. //    procedure SetMsg(MsgName: String);
  23.   published
  24.     property FileName: TFileName read FFileName write SetFileName;
  25.     property LngINISupp: TLngINISupp read FLngINISupp write SetLngINISupp;
  26.   end;
  27.  
  28. var
  29.   AppIniMsg: TIniFile;
  30.   Values: TStrings;
  31.   FNF: Bool = false;
  32.   FNP: Bool = false;
  33.   Opened: Bool = false;
  34.  
  35. procedure Register;
  36.  
  37. implementation
  38.  
  39. procedure Register;
  40. begin
  41.   RegisterComponents('LangINISupport', [TMsgINISupp]);
  42. end;
  43.  
  44. { TMsgINISupp }
  45.  
  46. procedure TMsgINISupp.CheckFile(FN: TFileName);
  47. var
  48.  strm: TMemoryStream;
  49. begin
  50.   strm := TMemoryStream.Create;
  51.   if FN = '' then
  52.     begin
  53.       ShowMessage('ERROR!!!' + #13#10 + 'File not preset!');
  54.       FNP := true;
  55.     end
  56.   else
  57.     begin
  58.       try
  59.         FNP := false;
  60.         strm.LoadFromFile(FN);
  61.        except
  62.         ShowMessage('WARNING!!!' + #13#10 + ' Language File Not Found! Its now creating a new!');
  63.         FNF := true;
  64.       end;
  65.     end;
  66.   strm.Free;
  67. end;
  68.  
  69. procedure TMsgINISupp.Open;
  70. begin
  71.   if ((FFileName = '') and (FLngINISupp <> nil)) then FFileName := FLngINISupp.FileName;
  72.   CheckFile(FFileName);
  73.   if FNP = true then abort;
  74.   Values := TStringList.Create;
  75.   Opened := true;
  76. end;
  77.  
  78. procedure TMsgINISupp.Close;
  79. begin
  80.   FFileName := '';
  81.   Opened := false;
  82. end;
  83.  
  84. function TMsgINISupp.GetMsg(MsgName: String):String;
  85. var
  86.  FMsg, RMsg: String;
  87.  p: Integer;
  88. begin
  89.   if Opened = false then Open;
  90.   AppIniMsg := TIniFile.Create(FFileName);
  91.   FMsg := AppIniMsg.ReadString('Project_Messages', MsgName, 'ERROR');
  92.   RMsg := '';
  93.   p := pos('"', FMsg);
  94.   if p <> 0 then
  95.     begin
  96.       while Length(FMsg) <> 0 do
  97.         begin
  98.           p := pos('"', FMsg);
  99.           RMsg := RMsg + Copy(FMsg, 1, p - 1) + #13#10;
  100.           Delete(FMsg, 1, p + 7);
  101.         end;
  102.       Result := RMsg;
  103.     end
  104.   else
  105.     Result := FMsg;
  106.   AppIniMsg.Free;
  107. end;
  108. {
  109. procedure TMsgINISupp.SetMsg(MsgName: String);
  110. begin
  111.   CheckFile(FFileName);
  112.   if Opened = false then Open;
  113. end;
  114. }
  115. procedure TMsgINISupp.SetLngINISupp(const Value: TLngINISupp);
  116. begin
  117.   FLngINISupp := Value;
  118.   FFileName := FLngINISupp.FileName;
  119. end;
  120.  
  121. procedure TMsgINISupp.SetFileName(const Value: TFileName);
  122. begin
  123.   FFileName := ExtractFileDir(ParamStr(0)) + '\' + ExtractFileName(Value);
  124. end;
  125.  
  126. end.
  127.