随笔 - 1191  文章 - 26 评论 - 2217 trackbacks - 108

提示1: 点击 标题 可进入首页;   提示2: 从搜索引擎中搜索 万一 可迅速找到这里.

随笔分类(1285)

随笔档案(1147)

积分与排名

  • 积分 - 513357
  • 排名 - 35

最新评论

阅读排行榜

60天内阅读排行

本例效果图:



代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{从字符串到十六进制的函数}
function StrToHex(str: string; AEncoding: TEncoding): string;
var
  ss: TStringStream;
  i: Integer;
begin
  Result := '';
  ss := TStringStream.Create(str, AEncoding);
  for i := 0 to ss.Size - 1 do
    Result := Result + Format('%.2x ', [ss.Bytes[i]]);
  ss.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo2.Text := StrToHex(Memo1.Text, TEncoding.ASCII);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Memo2.Text := StrToHex(Memo1.Text, TEncoding.Unicode);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Memo2.Text := StrToHex(Memo1.Text, TEncoding.UTF7);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  Memo2.Text := StrToHex(Memo1.Text, TEncoding.UTF8);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  Memo2.Text := StrToHex(Memo1.Text, TEncoding.Default);
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  Memo2.Text := StrToHex(Memo1.Text, TEncoding.BigEndianUnicode);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Caption := 'To ASCII';
  Button2.Caption := 'To Unicode';
  Button3.Caption := 'To UTF7';
  Button4.Caption := 'To UTF8';
  Button5.Caption := 'To Default';
  Button6.Caption := 'To BigEndianUnicode';
end;

end.

窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 156
  ClientWidth = 353
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 0
    Top = 0
    Width = 145
    Height = 88
    Align = alLeft
    Lines.Strings = (
      'Memo1')
    ScrollBars = ssVertical
    TabOrder = 0
  end
  object Memo2: TMemo
    Left = 157
    Top = 0
    Width = 196
    Height = 88
    Align = alRight
    Lines.Strings = (
      'Memo2')
    ScrollBars = ssVertical
    TabOrder = 1
  end
  object Panel1: TPanel
    Left = 0
    Top = 88
    Width = 353
    Height = 68
    Align = alBottom
    TabOrder = 2
    object Button1: TButton
      Left = 16
      Top = 6
      Width = 73
      Height = 25
      Caption = 'Button1'
      TabOrder = 0
      OnClick = Button1Click
    end
    object Button2: TButton
      Left = 95
      Top = 6
      Width = 74
      Height = 25
      Caption = 'Button2'
      TabOrder = 1
      OnClick = Button2Click
    end
    object Button3: TButton
      Left = 175
      Top = 6
      Width = 82
      Height = 25
      Caption = 'Button3'
      TabOrder = 2
      OnClick = Button3Click
    end
    object Button4: TButton
      Left = 263
      Top = 6
      Width = 74
      Height = 25
      Caption = 'Button4'
      TabOrder = 3
      OnClick = Button4Click
    end
    object Button5: TButton
      Left = 16
      Top = 37
      Width = 96
      Height = 25
      Caption = 'Button5'
      TabOrder = 4
      OnClick = Button5Click
    end
    object Button6: TButton
      Left = 130
      Top = 37
      Width = 207
      Height = 25
      Caption = 'Button6'
      TabOrder = 5
      OnClick = Button6Click
    end
  end
end

posted @ 2008-09-05 10:33 万一 阅读(93) | 评论 (0)编辑
本例效果图:



代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{读文件为十六进制字符的函数}
function ReadFileToHex(FileName: string): string;
var
  bs: TBytesStream;
  i: Integer;
begin
  Result := '';
  if not FileExists(FileName) then Exit;

  bs := TBytesStream.Create;
  bs.LoadFromFile(FileName);
  for i := 0 to bs.Size - 1 do
    Result := Result + Format('%.2x ', [bs.Bytes[i]]);
  bs.Free;
end;

{测试}
procedure TForm1.Button1Click(Sender: TObject);
const
  FilePath = 'c:\temp\Text.txt';
begin
  Memo1.Lines.SaveToFile(FilePath);
  Memo2.Text := ReadFileToHex(FilePath);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Caption := '保存并读出十六进制 (注意读出的 0D 0A 是换行符)';
end;

end.

窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 149
  ClientWidth = 339
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 0
    Top = 0
    Width = 160
    Height = 124
    Align = alLeft
    Lines.Strings = (
      'Memo1')
    ScrollBars = ssVertical
    TabOrder = 0
  end
  object Memo2: TMemo
    Left = 179
    Top = 0
    Width = 160
    Height = 124
    Align = alRight
    Lines.Strings = (
      'Memo2')
    ScrollBars = ssVertical
    TabOrder = 1
  end
  object Button1: TButton
    Left = 0
    Top = 124
    Width = 339
    Height = 25
    Align = alBottom
    Caption = 'Button1'
    TabOrder = 2
    OnClick = Button1Click
  end
end

posted @ 2008-09-04 17:28 万一 阅读(103) | 评论 (1)编辑

制作步骤:

1、添加一个 TImageList: ImageList1, 然后载入些图标;

2、添加两个 TPopupMenu: PopupMenu1、PopupMenu2, 并分别添加些菜单项;

3、添加一个 TToolBar 控件: ToolBar1, 通过其右键菜单 New Button 添加两个按钮: ToolButton1、ToolButton2;

4、选择属性:
    ToolBar1.Images := ImageList1;
    ToolButton1.Style := tbsDropDown;
    ToolButton2.Style := tbsDropDown;
    ToolButton1.DropdownMenu := PopupMenu1;
    ToolButton2.DropdownMenu := PopupMenu2;

设计时图:



运行时图:



posted @ 2008-09-03 14:43 万一 阅读(129) | 评论 (5)编辑
问题来源: http://www.cnblogs.com/del/archive/2008/09/03/989467.html#1306651

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
const
  str1 = 'aaa';
  str2 = 'bbb';
var
  List: TStrings;
begin
  List := TStringList.Create;
  List.Add(str1 + '=123');
  List.Add(str2 + '=456');

  ShowMessage(List.Values['aaa']); {123}
  ShowMessage(List.Values['bbb']); {456}

  List.Free;
end;

end.

posted @ 2008-09-02 22:59 万一 阅读(219) | 评论 (2)编辑

这里有所有相关参数的解释: http://www.cnblogs.com/del/archive/2008/04/15/1154359.html

//最大化窗口
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style := Params.Style or WS_MAXIMIZE; {WS_MINIMIZE 是最小化}
end;


//取消系统菜单(如果没法关闭就用 Alt+F4 吧)
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style := Params.Style and not WS_SYSMENU;
end;


//取消能够调整大小的边框
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style := Params.Style and not WS_THICKFRAME;
end;


//在所有非顶层窗口的最上面
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_TOPMOST;
end;


//工具窗口
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_TOOLWINDOW;
end;


//带阴影边界, 有这 MDI 窗口的视觉
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_CLIENTEDGE;
end;


//带帮助按钮
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style := Params.Style and not (WS_MINIMIZEBOX or WS_MAXIMIZEBOX);
  Params.ExStyle := Params.ExStyle or WS_EX_CONTEXTHELP;
end;

posted @ 2008-09-02 17:18 万一 阅读(121) | 评论 (0)编辑