Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Intento dotar al TShape de Texto pero no consigo que funcione (https://www.clubdelphi.com/foros/showthread.php?t=88348)

bulc 24-05-2015 09:14:39

Intento dotar al TShape de Texto pero no consigo que funcione
 
He encontrado este código que me vendría muy bien pero no consigo hacerlo funcionar. ¿Seríais tan amables de decirme por qué no funciona?
Código Delphi [-]
type
  TShape = class(ExtCtrls.TShape); //interposer class

  TForm1 = class(TForm)
    Shape1: TShape;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
    Shape1.Canvas.Font.Name :='Arial';// set the font 
    Shape1.Canvas.Font.Size  :=20;//set the size of the font
    Shape1.Canvas.Font.Color:=clBlue;//set the color of the text
    Shape1.Canvas.TextOut(10,10,'1999');
end;
Gracias
bulc

Casimiro Notevi 24-05-2015 09:52:14

¿Por qué no funciona, qué sale, qué dice, qué muestra...?

nlsgarcia 24-05-2015 14:19:14

bulc,

Cita:

Empezado por bulc
...este código que me vendría muy bien pero no consigo hacerlo funcionar...

:rolleyes:

Pregunto:

1- ¿Que versión de Windows y de cuantos bits (32/64) utiliza tu aplicación?.

2- ¿Que versión de Delphi utiliza tu aplicación?.

3- ¿Puedes detallar o mostrar el problema señalado?.

Revisa este código:
Código Delphi [-]
unit Unit1;

interface

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

type

  TShape = class(ExtCtrls.TShape);

  TForm1 = class(TForm)
    Shape1: TShape;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
   Number : Integer;

begin

    Randomize;
    Number := RandomRange(1999,2016);

    Shape1.Canvas.Brush.Color := clSkyBlue;
    Shape1.Canvas.Font.Name :='Arial';
    Shape1.Canvas.Font.Size := 30;
    Shape1.Canvas.Font.Color := clBlue;
    Shape1.Canvas.TextOut(10,10,IntToStr(Number));

end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, Implementa un TShape e imprime texto sobre el mismo de forma dinámica, como se muestra en la siguiente imagen:



Espero sea útil :)

Nelson.

bulc 24-05-2015 16:32:07

Pues me faltaba algo...
 
Ya veo que no veo. He puesto en el Uses Vcl.ExtCtrls, System.Math; y funciona. !Qué cosas!
No sé qué decir así que te doy las gracias. Se me quita un peso de encima.
Saludos,
bulc


La franja horaria es GMT +2. Ahora son las 06:49:08.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi