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

📄 common.pas

📁 被系统名叫生产信息管理系统
💻 PAS
字号:
unit Common;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Forms, ExtCtrls, StdCtrls,
  IniFiles, DateUtils;

  procedure ShowPanel(const ChildFormPanel,MainFormPanel: TPanel);
  {
    函数功能:把子面板上的所有控件,全部拼接到主面板上。
    参数说明:
        ChildFormPanel:子面板名称;
         MainFormPanel:主面板名称;
  }

  function Base64Encode(const s: string): string;
  function Base64Decode(const s: string): string;
  function ReadIniFileFloat(StrFileName, StrSection, StrIdent: String): Real;
  procedure WriteIniFileFloat(StrFileName, StrSection, StrIdent: String;
    WriteValue: Real);
  function ReadIniFileString(StrFileName, StrSection, StrIdent: String): String;
  procedure WriteIniFileString(StrFileName, StrSection, StrIdent,
    WriteValue: String);
  function SplitString(const Source, ch: String): TStrings;
  function DateTimeToReal(const StartValue,EndValue:TDateTime):Real;


implementation

procedure ShowPanel(const ChildFormPanel,MainFormPanel: TPanel);
var
    I,J,intSelectResult:Integer;
    panChildPanelName:TPanel;
begin
    {列举主面板中的所有控件,查找是否存在子面板控件ChildPanel}
    for  I:= 0 to MainFormPanel.ControlCount-1 do
    begin
    if MainFormPanel.Controls[I].Name = 'panChild' then
    begin
        panChildPanelName:=(MainFormPanel.controls[I] as TPanel);
        intSelectResult:=Messagebox(Application.Handle,
            '已经打开了一个页面,是否关闭此页面打开另一页面?',
                   '错误',20);
        if intSelectResult=6 then
        begin
            for J:=0 to panChildPanelName.ControlCount -1 do
                if panChildPanelName.Controls[J].Name='cmdClose' then
                    (panChildPanelName.Controls[J] as TButton).Click;
        end
        else
            Exit;
        end;
    end;
    {如果在主面板中没有子面板控件,则将子面板的父窗体设置主面板,
     完成面板的拼接}
    ChildFormPanel.Parent := MainFormPanel;
    ChildFormPanel.Left := 0;
    ChildFormPanel.Top := 0;
end;

function Base64Encode(const s: string): string;
var
  i,c1,c2,c3: Integer;
  m,n: Integer;
const
  Base64: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
begin
  Result := '';
  m:=1;
  n:=0;
  for i := 1 to (Length(s) div 3) do
  begin
    c1 := Ord(s[m]);
    c2 := Ord(s[m+1]);
    c3 := Ord(s[m+2]);
    m:=m+3;
    Result := Result+base64[(c1 shr 2)and $3F+1];
    Result := Result+base64[((c1 shl 4)and $30) or ((c2 shr 4)and $0F)+1];
    Result := Result+base64[((c2 shl 2)and $3C) or ((c3 shr 6)and $03)+1];
    Result := Result+base64[c3 and $3F+1];
    n:=n+4;
    if(n = 76)then
    begin
       n:=0;
       Result := Result+#13#10;
    end;
  end;
  if (Length(s) mod 3)=1 then
  begin
    c1 := Ord(s[m]);
    Result := Result+base64[(c1 shr 2)and $3F+1];
    Result := Result+base64[(c1 shl 4)and $30+1];
    Result := Result+'=';
    Result := Result+'=';
  end;
  if (Length(s) mod 3)=2 then
  begin
    c1 := Ord(s[m]);
    c2 := Ord(s[m+1]);
    Result := Result+ base64[(c1 shr 2)and $3F+1];
    Result := Result+ base64[((c1 shl 4)and $30) or ((c2 shr 4)and $0F)+1];
    Result := Result+base64[(c2 shl 2)and $3C+1];
    Result := Result+ '=';
  end;
end;

function Base64Decode(const s: string): string;
var
  i,m,n: Integer;
  c1,c2,c3,c4: Integer;
const
  Base64: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
begin
  Result := '';
  n:=1;
  m:=Length(s);
  if s[m]='='then m:=m-1;
  if s[m]='='then m:=m-1;
  for i:=1 to m div 4 do
  begin
    c1:=Pos(s[n],Base64)-1;
    c2:=Pos(s[n+1],Base64)-1;
    c3:=Pos(s[n+2],Base64)-1;
    c4:=Pos(s[n+3],Base64)-1;
    n:=n+4;
    Result:=Result+Chr(((c1 shl 2)and $FC)or((c2 shr 4)and $3));
    Result:=Result+Chr(((c2 shl 4)and $F0)or((c3 shr 2)and $0F));
    Result:=Result+Chr(((c3 shl 6)and $C0)or c4);
  end;
  if m mod 4=2 then
  begin
    c1:=Pos(s[n],Base64)-1;
    c2:=Pos(s[n+1],Base64)-1;
    Result:=Result+Chr(((c1 shl 2)and $FC)or((c2 shr 4)and $3));
  end;

  if m mod 4=3 then
  begin
    c1:=Pos(s[n],Base64)-1;
    c2:=Pos(s[n+1],Base64)-1;
    c3:=Pos(s[n+2],Base64)-1;
    Result:=Result+Chr(((c1 shl 2)and $FC)or((c2 shr 4)and $3));
    Result:=Result+Chr(((c2 shl 4)and $F0)or((c3 shr 2)and $0F));
  end;

end;

function ReadIniFileFloat(StrFileName, StrSection, StrIdent: String): Real;
var
    OpenIniFileName: TIniFile;
begin
    {打开Ini文件}
    OpenIniFileName := TIniFile.Create(StrFileName);
    {调用Delphi自身的函数,读取Ini文件整型数值}
    Result := OpenIniFileName.ReadFloat(StrSection, StrIdent, - 1);
    {关闭Ini文件}
    OpenIniFileName.Free;
end;

procedure WriteIniFileFloat(StrFileName, StrSection, StrIdent: String;
    WriteValue: Real);
var
    OpenIniFileName: TIniFile;
begin
    {打开Ini文件}
    OpenIniFileName := TIniFile.Create(StrFileName);
    {调用Delphi自身的函数,向Ini文件写入整型数值}
    OpenIniFileName.WriteFloat(StrSection, StrIdent, WriteValue);
    {关闭Ini文件}
    OpenIniFileName.Free;
end;

function ReadIniFileString(StrFileName, StrSection, StrIdent: String): String;
var
    OpenIniFileName: TIniFile;
begin
    {打开Ini文件}
    OpenIniFileName := TIniFile.Create(StrFileName);
    {调用Delphi自身的函数,读取Ini文件字符串}
    Result := OpenIniFileName.ReadString(StrSection, StrIdent, '');
    {关闭Ini文件}
    OpenIniFileName.Free;
end;

procedure WriteIniFileString(StrFileName, StrSection, StrIdent,
    WriteValue: String);
var
    OpenIniFileName: TIniFile;
begin
    {打开Ini文件}
    OpenIniFileName := TIniFile.Create(StrFileName);
    {调用Delphi自身的函数,向Ini文件写入字符串}
    OpenIniFileName.WriteString(StrSection, StrIdent, WriteValue);
    {关闭Ini文件}
    OpenIniFileName.Free;
end;

function SplitString(const Source, ch: String): TStrings;
var
    temp: String;
    i: Integer;
begin
    Result := TStringList.Create;
    temp := Source;
    i := pos(ch, Source);
    while i <> 0 do
    begin
        Result.Add(copy(temp, 0, i - 1));
        Delete(temp, 1, i);
        i := pos(ch, temp);
    end;
    Result.Add(temp);
end;

function DateTimeToReal(const StartValue,EndValue:TDateTime):Real;
var
    TempValue:TDateTime;
    intDayValue:Integer;
begin
    Result:=0;
    TempValue:=EndValue-StartValue;
    intDayValue:=DayOf(EndValue)-DayOf(StartValue);
    Result:=HourOf(TempValue)+intDayValue*8;
    Result:=Result+MinuteOf(TempValue)/60;
end;

end.

⌨️ 快捷键说明

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