| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2271 人关注过本帖
标题:delphi新手,一个简单的问题求解
只看楼主 加入收藏
qq339590913
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-10-11
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
delphi新手,一个简单的问题求解
做一个小程序:定义一个类,包含两个整形(x,y)和一个字符串(s)及方法output。output实现在窗体上的x,y位置,输出字符串s。
搜索更多相关主题的帖子: 字符串 
2013-10-11 15:54
veketdelphi
Rank: 5Rank: 5
等 级:职业侠客
帖 子:67
专家分:374
注 册:2013-4-8
收藏
得分:10 
这个要 自己写个类
重载了 构造函数
程序代码:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
type/////
  TMyClass = class
  private
    x:Integer;
    y:integer;
    s:string;
  public
    constructor Create(xx:Integer;yy:Integer;ss:string);overload;
    procedure out;
  end;///////
var
  Form1: TForm1;

implementation

{$R *.dfm}
constructor TMyClass.Create(xx:Integer;yy:Integer;ss:string);/////
begin
  x := xx;
  y := yy;
  s := ss;
end;
procedure TMyClass.out;/////
begin
  Form1.Canvas.TextOut(x, y, s);/////
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  a:TMyClass;////
begin
  a := TMyClass.Create(100, 200, '百度知道');////
  a.out;////
  a.Free;////
end;

end.

2013-10-11 19:44
haiou327
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:22
专家分:107
注 册:2009-4-26
收藏
得分:10 
程序代码:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  TcustCls = class
  private
    Fx, Fy: Integer;
    Fs: string;
  public
    procedure outPut(x, y:Cardinal; s: string);
  end;
var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure Tcustcls.outPut(x, y: Cardinal; s: string);
begin
  if (x > 0) and (y > 0) then
  begin
    fx := x;
    fy := y;
    fs := s;
    Form1.Canvas.TextOut(fx, fy, fs);
  end
  else
    ShowMessage('坐标错误');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  myText: TcustCls;
begin
  myText := TcustCls.Create;
  myText.outPut(60, 50, '代码测试.....');
  myText.Free;
end;

end.


[ 本帖最后由 haiou327 于 2013-10-12 12:59 编辑 ]
2013-10-11 22:30
haiou327
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:22
专家分:107
注 册:2009-4-26
收藏
得分:0 
在桌面输出
程序代码:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  TcustCls = class
  private
    Fx, Fy: Integer;
    Fs: string;
  public
    procedure outPut(x, y: Cardinal; s: string);
  end;
var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure Tcustcls.outPut(x, y: Cardinal; s: string);
var
  cvs: TCanvas;
begin
  if (x > 0) and (y > 0) then
  begin
    fx := x;
    fy := y;
    fs := s;
    try
    cvs := TCanvas.Create;
    cvs.Handle := GetDc(0);
    SetBkMode(cvs.Handle, TRANSPARENT);
    cvs.Font.Name := '宋体';
    cvs.Font.Style := [fsBold];
    cvs.font.Color := clRed;
    cvs.Font.Size := 50;
    cvs.TextOut(Fx, Fy, s);
    finally
    FreeAndNil(cvs);
    end;
  end
  else
    ShowMessage('坐标错误');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  myCls: TcustCls;
  s: string;
begin
  s := '夕阳西下,小桥流水人家';
  myCls := TcustCls.Create;
  myCls.outPut(100, 100, s);
  myCls.Free;
end;
end.
2013-10-13 13:33
快速回复:delphi新手,一个简单的问题求解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026699 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved