my_api_for_systemini.pas

来自「是和Delphi 编程精选集锦书本配套的源码」· PAS 代码 · 共 117 行

PAS
117
字号
// Author:Youzhen
// Date: 2000/08/09
// Version: 1.0
//
// This Is A Dll File For Config ScreenSave
//
// Don't Use TString In Dll File !
// Use shortstring Instead of TString !
//
// Topic Function:
//         GetProvideProfileString
//         WriteProvideProfileString
//         GetMem
//         StrPCopy
//         FreeMem
//
//************************************************//

unit My_API_for_Systemini;

interface

uses
  Windows, SysUtils;

procedure My_GetPrivateProfileString(
            My_lpAppName,
            My_lpKeyName,
            My_lpDefault:shortstring;
            var My_lpReturnedString:shortstring;
            My_nSize:dword;
            My_lpFileName:shortstring);

procedure My_WritePrivateProfileString(
            My_lpAppName,
            My_lpKeyName,
            My_String,
            My_lpFileName:shortstring);

implementation

                                                procedure My_GetPrivateProfileString(
            My_lpAppName,
            My_lpKeyName,
            My_lpDefault:shortstring;
            var My_lpReturnedString:shortstring;
            My_nSize:dword;
            My_lpFileName:shortstring);

var lpAppName,  // points to section name
    lpKeyName,	// points to key name
    lpDefault,  // points to default string
    lpReturnedString:pchar;  // points to destination buffer
    nSize:dword;	// size of destination buffer
    lpFileName:pchar;

  begin
    GetMem(lpAppName,100);
    GetMem(lpKeyName,100);
    GetMem(lpDefault,100);
    GetMem(lpReturnedString,100);
    GetMem(lpFileName,100);

    StrPCopy(lpAppName,My_lpAppName);
    StrPCopy(lpKeyName,My_lpKeyName);
    StrPCopy(lpDefault,My_lpDefault);
    StrPCopy(lpFileName,My_lpFileName);
    
    nSize:=My_nSize;
    //%%%即先为返回字符串指定足够的空间%%%

    GetPrivateProfileString(
        lpAppName,lpKeyName,lpDefault,lpReturnedString,
        nSize,lpFileName);

    My_lpReturnedString:=StrPas(lpReturnedString);

    FreeMem(lpAppName,100);
    FreeMem(lpKeyName,100);
    FreeMem(lpDefault,100);
    FreeMem(lpReturnedString,100);
    FreeMem(lpFileName,100);
  end;


procedure My_WritePrivateProfileString(
            My_lpAppName,
            My_lpKeyName,
            My_String,
            My_lpFileName:shortstring);

var lpAppName,	// pointer to section name
    lpKeyName,	// pointer to key name
    lpString,	// pointer to string to add
    lpFileName:PChar; 	// pointer to initialization filename

  begin
    GetMem(lpAppName,100);
    GetMem(lpKeyName,100);
    GetMem(lpString,100);
    GetMem(lpFileName,100);

    StrPCopy(lpAppName,My_lpAppName);
    StrPCopy(lpKeyName,My_lpKeyName);
    StrPCopy(lpString,My_String);
    StrPCopy(lpFileName,My_lpFileName);

    WritePrivateProfileString(
      lpAppName,lpKeyName,lpString,lpFileName);

    FreeMem(lpAppName,100);
    FreeMem(lpKeyName,100);
    FreeMem(lpString,100);
    FreeMem(lpFileName,100);
  end;
end.

⌨️ 快捷键说明

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