Separador Component

Delphi Source
Joao Paulo Schwarz Schuler
unit UTSEP;
{ componente que divide uma linha string
  em palavras }
{ component that divide a line string in
  words }
interface

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

type
  TSeparador = class(TComponent)
  private
    { Private declarations }
    FItens:TStringList;
    FLine:String;
    procedure Sepal(LINHA:string);
   { separa linha em palavras }
   { divide a line string in words }

  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure UpCaseAll;
    { UpCase em todas as palavras }
    { UpCase in all words}

  published
    { Published declarations }
    property Items:TStringList read FItens write FItens;
    property Line:String read FLine Write Sepal;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Tekcon', [Tseparador]);
end;

constructor TSeparador.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FItens:=TStringList.Create;
{MessageDlg('Create Executed',
    mtInformation, [mbOk], 0)}
end;

destructor TSeparador.Destroy;
begin
FItens.Free;
inherited Destroy;
{MessageDlg('Destroy Executed',
    mtInformation, [mbOk], 0)}
end;

procedure TSeparador.Sepal(LINHA:string);
{ separa linha em palavras }
{ divide a line string in words }
var A:word;
    L:char; {LETRA}
    S:String;{ palavra }
begin
FItens.Clear;
FLine:=Linha;
Linha:=Linha+' ';
L:=' ';
S:='';
for A:=1 to length(LINHA) do
    begin
    L:=LINHA[A];
    if (L<>' ') then
       begin
          S:=S+L
       end
     else
       begin
       if (LINHA[pred(A)]<>' ') and (A<>1) and (S<>'') then
          begin
          FItens.Add(S);
          S:='';
          end
       end
    end; { of for }
{if P[NP]='' then dec(NP);}
end;

procedure TSeparador.UpCaseAll;
{ UpCase em todas as palavras }
{ UpCase in all words}
var I:Integer;
begin
 for I := 0 to pred(FItens.Count) do
    FItens.Strings[I] := UpperCase(FItens.Strings[I]);
end;

end.
{---------------------------------------------------------------------------------------}
			Exemplo de Uso
			Use Example
{---------------------------------------------------------------------------------------}
unit Uso;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Edit1: TEdit;
    OKbut: TButton;
    Separador1: TSeparador;
    Button1: TButton;
    procedure OKbutClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure Refresh;
    public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Refresh;
var I:integer;
begin
Memo1.Clear;
for I:=0 to pred(Separador1.Items.Count) do
    begin
    Memo1.Lines.add(Separador1.Items.Strings[I]);
    end;
end;


procedure TForm1.OKbutClick(Sender: TObject);
begin
Separador1.Line:=Edit1.Text;
Refresh;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Separador1.UpCaseAll;
Refresh;
end;

end.
{---------------------------------------------------------------------------------------}

Return to the Home Page
Return to the Fontes em Delphi 2.0