⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registry.htm

📁 对于学习很有帮助
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!-- This document was created with HomeSite v2.5 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">

<HTML>
<HEAD>
	<TITLE>UDDF - Registry</TITLE>
	<META NAME="Description" CONTENT="Registry and Inifile section of the Delphi Developers FAQ" >
	<META NAME="KeyWords" CONTENT="" >

</HEAD>

<BODY  bgcolor="#FFFFFF">
<CENTER>
<IMG SRC="../images/uddf.jpg"> </CENTER>
<HR SIZE="6" color="#00FF00">


<CENTER><FONT SIZE="7" FACE="Arial Black" COLOR="RED">Registry</FONT></CENTER>
<P><H1><A NAME="registry0">Registry-- Accessing it, and using it instead of WIN.INI</P></A></H1>
<P><I>From: "Mark Goodrich" &lt;mgood@ns.net></I></P>

<HR><PRE>uses
   Registry, Windows;

var
   TheReg: TRegistry;
   KeyName: String;
   ValueStr: String;

begin
   TheReg := TRegistry.Create;
   try
      TheReg.RootKey := HKEY_CURRENT_USER;
      KeyName := 'Software\MyTinyApp\StartUp;
      if TheReg.OpenKey(KeyName, False) then
      begin
         ValueStr := TheReg.ReadString('WorkPath');
         TheReg.CloseKey;
      end;
   finally
      TheReg.Free;
   end;
end;
</PRE><HR>


<P>Also note, the correct place to store the path to your application's EXE under the Win95 registry is in:</P>

<HR><PRE>HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\AppPaths\MYAPP.EXE</PRE><HR>

<P>Store the complete path to your app as the default value under that key.</P>
<P>Regstr.pas defines a constant for this path up through ...\App Paths\ as <TT>REGSTR_PATH_APPPATHS.</TT></P>

<P>Storing the path to your application's EXE here will allow a user to simply type MYAPP (or whatever its name is) in Start|Run 
on the taskbar and your application will launch.  Here's an example of how to create it:</P>

<HR><PRE>uses
   Registry, Regstr;

var
   TheReg: TRegistry;
   KeyName: String;

begin
   TheReg := TRegistry.Create;
   try
      {Check AppPath setting, update if necessary}
      TheReg.RootKey := HKEY_LOCAL_MACHINE;
      KeyName := REGSTR_PATH_APPPATHS + ExtractFileName(Application.ExeName);
      if TheReg.OpenKey(KeyName, True) then
      begin
         if CompareText(TheReg.ReadString(''), Application.ExeName) &lt;> 0 then
            TheReg.WriteString('', Application.ExeName);
         TheReg.CloseKey;
      end;
   finally
      TheReg.Free;
   end;
end;
</PRE><HR>

<P><H1><A NAME="registry1">How to get a registered OCX?</P></A></H1>

<P>You are right: before an OCX can be used, it must be
registered with the System Registry.</P>

<P>Suppose the OCX you want to use is called "test.ocx".</P>
<P>Try this code:</P>

<HR><PRE>var
  OCXHand: THandle;
  RegFunc: TDllRegisterServer;   //add OLECtl to the uses clause
begin
  OCXHand:= LoadLibrary('c:\windows\system\test.ocx');
  RegFunc:= GetProcAddress(OCXHand, 'DllRegisterServer');  //case
sensitive?
  if RegFunc &lt;> 0 then ShowMessage('Error!');
  FreeLibrary(OCXHand);
end;
</PRE><HR>

<P>You can the same way unregister the OCX: all you have to do is
to replace 'DllRegisterServer' by 'DllUnregisterServer'.</P>

<P>You should add some validation code: "Does the file exist",
"Was the call to LoadLibrary successful?", ...</P>

<P>Some explanations:</P>

<P>        An OCX is a special form of dll, so you can load it in memory  with a call to the LoadLibrary() API function. An OCX exports two  
functions to register and unregister the control. You then use  GetProcAddress to obtain the address of these functions. 
You just have then to call the appropriate function. And that's it! You can explore the Registry (with regedit.exe) to verify that the OCX is registered.</P>

<P><H1><A NAME="registry2">Win95 installation directory.</P></A></H1>
<P><I>From: "None of your Business" &lt;someone@someplace.org></I></P>

<HR><PRE>function FindWindowsDir : string;
var
pWindowsDir : array [0..255] of Char;
sWindowsDir : string;
begin
// GetWindowsDirectory(LPTSTR,UINT);
// LPTSTR  lpBuffer,    // address of buffer for Windows directory
// UINT  uSize          // size of directory buffer
   GetWindowsDirectory (pWindowsDir, 255);
    sWindowsDir := StrPas (pWindowsDir);
    Result := sWindowsDir ;
end;
</PRE><HR>

<P><H1><A NAME="registry3">How to get time zone info (DST) from registry?</P></A></H1>
<P><I>From: rds@melbpc.org.au (Robert Small)</I></P>

<PRE>>
>HKEYLocal Machine/Software/Microsoft/Windows/CurrentVersion/TimeZones/
>
>is the place where Timezone infos are stored in the registry. The
>binary 'TZI' entry should be the info for start and end times of
>daylight saving times. Anyone has an idea how to extract the dates
>from this value?
>
</PRE>
<P>The TZI entry seems to be structured as follows:</P>

<HR><PRE>int32 Bias;             // Minutes from GMT
                        // (Sydney -600; 0xfffffda8;
                        // or a8, fd, ff, ff)
int32 StandardBias;     // Bias for Standard time (0)
int32 DaylightBias;     // Bias for Daylight time (-60
                        // or 0xffffffc4 )
int16 ??                          // 0
int16 StandardStartMonth;         // 3 => March
int16 StandardStartDayOfWeek??;   // 0 => Sun
int16 StandardStartDOWoccurrence; // 1 => 1st
int16 StandardStartHour;          // 2 => 02:00:00.00
int16 StandardStartMins??;        // 0 => 02:00:00.00
int16 StandardStartSecs??;        // 0 => 02:00:00.00
int16 StandardStartHunds??;       // 0 => 02:00:00.00
int16 ??                          // 0
int16 DaylightStartMonth;         // 0x0a (10) => October
int16 DaylightStartDayOfWeek??;   // 0 => Sun
int16 DaylightStartDOWoccurrence; // 5 => last
int16 DaylightStartHour;          // 2 => 02:00:00.00
int16 DaylightStartMins??;        // 0 => 02:00:00.00
int16 DaylightStartSecs??;        // 0 => 02:00:00.00
int16 DaylightStartHunds??;       // 0 => 02:00:00.00
</PRE><HR>

<P><H1><A NAME="registry4">TStringList in TIniFile</P></A></H1>
<P><I>From: Vito Palmisano &lt;vi.palmisano@area.ba.cnr.it></I></P>

<P><I>From "Visual Developer Journal" June/July 1996 page 108,  unit IniStr written by Ed Jordan:</I></P>

<HR><PRE>unit IniStr;
{Written by Ed Jordan}
interface

uses Classes;

type
TIniStringlist = class( TStringList )
public
  procedure LoadFromIni( const FileName, Section: string);
  procedure SaveToIni( const FileName, Section: string);
end;

implementation

uses IniFiles, SysUtils;

procedure TIniStringList.LoadFromIni( const FileName,Section: string);
var
  Index: Integer;
  Line: string;
begin
  with TIniFile.Create( FileName ) do
  try
    ReadSectionValues( Section, Self);
    for Index:= 0 to Count - 1 do
    begin
      { Remove the identifier name ...}
      Line:= Values[ IntToStr( Index ) ];
      { Delete the tilde ... }
      System.Delete( Line, 1, 1);
      Strings[ Index ]:= Line;
    end;
  finally
    Free;
  end;
end;

procedure TIniStringList.SaveToIni( const FileName, Section: string);
var
  Index: Integer;
  Line: string;
begin
  with TIniFile.Create( FileName ) do
  try
    EraseSection( Section );
    for Index:= 0 to Count - 1 do
    begin
      { Preserve leading white space, blank lines ...}
      Line:= '~' + Strings[ Index ];
      WriteString( Section, IntToStr( Index ), Line);
    end;
  finally
    Free;
  end;
end;

end.


Usage:

var
  L: TIniStringList;
begin
  L:= TIniStringList.Create;
  L.LoadFromIni('MyFile.Ini', 'Alati');
  {process L..}
  L.Free;
end.
</PRE><HR>

<P><H1><A NAME="registry5">Store Fontstyle in INI</P></A></H1>
<P><I>From: jxidus@aol.com (JXidus)</I></P>

<P>My solution:  (to store the entire font, actually)</P>

<HR><PRE>function FontToStr(font: TFont): string;
procedure yes(var str:string);
begin
     str := str + 'y';
end;
procedure no(var str:string);
begin
     str := str + 'n';
end;
begin
     {encode all attributes of a TFont into a string}
     Result := '';
     Result := Result + IntToStr(font.Color) + '|';
     Result := Result + IntToStr(font.Height) + '|';
     Result := Result + font.Name + '|';
     Result := Result + IntToStr(Ord(font.Pitch)) + '|';
     Result := Result + IntToStr(font.PixelsPerInch) + '|';
     Result := Result + IntToStr(font.size) + '|';
     if fsBold in font.style then yes(Result) else no(Result);
     if fsItalic in font.style then yes(Result) else no(Result);
     if fsUnderline in font.style then yes(Result) else no(Result);
     if fsStrikeout in font.style then yes(Result) else no(Result);
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -