File->New ,在对话框中选 Unit,单击OK。在别的单元中的Uses中加入这个单元的单元名后,就可用这个单元里的内容。

解决方案 »

  1.   

    // a example
    unit MyLib;interfaceuses
       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ComCtrls,stdctrls;//ConnectToInternet打开一个IE窗口,并连接到对应网站
    function ConnnectToInternet(Addr:String):Integer;
    //CreateRotatedFont创建旋转字体
    function CreateRotatedFont(Font: TFont; Angle: Integer): HFont;
    //InputBox与VB类似的输入框
    function InputBox(const ACaption, APrompt: string;
      var Value: string): Boolean;
    implementationfunction ConnnectToInternet(Addr:String):Integer;
    var
     Rslt:LongBool;
     StartupInfo:TStartupInfo;
     ProcessInfo:TProcessInformation ;
     IEPath:array [0..MAX_PATH] of Char;
     IEName:String;
    begin
     GetWindowsDirectory(IEPath,MAX_PATH);
     IEName:=IEPath+'\Explorer.exe '+Addr; 
     FillChar(StartupInfo,sizeof(TStartupInfo),0);
     with StartupInfo do
       begin
        cb:=sizeof(TStartupInfo);
        dwFlags:=STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
        wShowWindow:=SW_MAXIMIZE;
       end;
    Rslt:=CreateProcess(nil,Pchar(IEName),nil,nil,false,
        NORMAL_PRIORITY_CLASS,nil,nil,StartupInfo,ProcessInfo);
    if Rslt then
     with ProcessInfo do
     begin
      WaitForInputIdle(hProcess,INFINITE);
      CloseHandle(hThread);
      CloseHandle(hProcess);
      Result:=0;
     end
     else Result:=GetLastError;
    end;function CreateRotatedFont(Font: TFont; Angle: Integer): HFont;
    var
      LogFont: TLogFont;
    begin
      FillChar(LogFont, SizeOf(LogFont), 0);
      with LogFont do begin
        lfHeight := Font.Height;
        lfWidth := 0;
        lfEscapement := Angle * 10;
        lfOrientation := 0;
        if fsBold in Font.Style then lfWeight := FW_BOLD
        else lfWeight := FW_NORMAL;
        lfItalic := Ord(fsItalic in Font.Style);
        lfUnderline := Ord(fsUnderline in Font.Style);
        lfStrikeOut := Byte(fsStrikeOut in Font.Style);
    {$IFDEF RX_D3}
        lfCharSet := Byte(Font.Charset);
        if AnsiCompareText(Font.Name, 'Default') = 0 then
          StrPCopy(lfFaceName, DefFontData.Name)
        else
          StrPCopy(lfFaceName, Font.Name);
    {$ELSE}
      {$IFDEF VER93}
        lfCharSet := Byte(Font.Charset);
      {$ELSE}
        lfCharSet := DEFAULT_CHARSET;
      {$ENDIF}
        StrPCopy(lfFaceName, Font.Name);
    {$ENDIF}
        lfQuality := DEFAULT_QUALITY;
        lfOutPrecision := OUT_DEFAULT_PRECIS;
        lfClipPrecision := CLIP_DEFAULT_PRECIS;
        case Font.Pitch of
          fpVariable: lfPitchAndFamily := VARIABLE_PITCH;
          fpFixed: lfPitchAndFamily := FIXED_PITCH;
          else lfPitchAndFamily := DEFAULT_PITCH;
        end;
      end;
      Result := CreateFontIndirect(LogFont);
    end;function InputBox(const ACaption, APrompt: string;
      var Value: string): Boolean;
    var
      Form: TForm;
      Prompt: TLabel;
      Edit: TEdit;
      DialogUnits: TPoint;
      ButtonTop, ButtonWidth, ButtonHeight: Integer;
    begin
      Result := False;
      Form := TForm.Create(Application);
      with Form do
        try
          Font.Handle:=GetStockObject(Default_Gui_font);
          Canvas.Font := Font;
          DialogUnits := GetAveCharSize(Canvas);
          BorderStyle := bsDialog;
          Caption := ACaption;
          ClientWidth := MulDiv(180, DialogUnits.X, 4);
          ClientHeight := MulDiv(63, DialogUnits.Y, 8);
          Position := poScreenCenter;
          Prompt := TLabel.Create(Form);
          with Prompt do
          begin
            Parent := Form;
            AutoSize := True;
            Left := MulDiv(8, DialogUnits.X, 4);
            Top := MulDiv(8, DialogUnits.Y, 8);
            Caption := APrompt;
          end;
          Edit := TEdit.Create(Form);
          with Edit do
          begin
            Parent := Form;
            Left := Prompt.Left;
            Top := MulDiv(19, DialogUnits.Y, 8);
            Width := MulDiv(164, DialogUnits.X, 4);
            MaxLength := 255;
            Text := Value;
            SelectAll;
          end;
          ButtonTop := MulDiv(41, DialogUnits.Y, 8);
          ButtonWidth := MulDiv(50, DialogUnits.X, 4);
          ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
          with TButton.Create(Form) do
          begin
            Parent := Form;
            Caption := '确定(&Y)';
            ModalResult := mrOk;
            Default := True;
            SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
              ButtonHeight);
          end;
          with TButton.Create(Form) do
          begin
            Parent := Form;
            Caption := '取消(&C)';
            ModalResult := mrCancel;
            Cancel := True;
            SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth,
              ButtonHeight);
          end;
          if ShowModal = mrOk then
          begin
            Value := Edit.Text;
            Result := True;
          end;
        finally
          Form.Free;
        end;
    end;
    end.