Ver Mensaje Individual
  #4  
Antiguo 02-03-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
CM6ISG,

Cita:
Empezado por CM6ISG
...estoy usado CportLib y el me devuelve a través del puerto Serial una Variable Str...tiene esta estructura... #PO0#SQS#EM0#FT0715000#FR0711200...necesito es separar esta cadena en 5 cadenas y asignarla a 5 nuevas variables...


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

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
   CRLF = #13#10;
   Output_CportLib = '#PO0' + CRLF + '#SQS' + CRLF + '#EM0' + CRLF + '#FT0715000' + CRLF + '#FR0711200' + CRLF;

var
   StrList : TStringList;
   Power, Qsl, Modo, FTX, FTR : String;

begin

   StrList := TStringList.Create;

   ExtractStrings(['#'], [], PChar(Output_CportLib), StrList);

   Power := StrList[0];
   Qsl := StrList[1];
   Modo := StrList[2];
   FTX := Copy(StrList[3],3,Length(StrList[3]));
   FTR := Copy(StrList[4],3,Length(StrList[4]));

   Memo1.Text := Output_CportLib;
   Edit1.Text := Output_CportLib;

   Edit2.Text := Power;
   Edit3.Text := Qsl;
   Edit4.Text := Modo;
   Edit5.Text := FTX;
   Edit6.Text := FTR;

   StrList.Free;

end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, Simula la lectura de un puerto serial separando la misma en 5 variables y visualizando esta por diferentes medios, como se muestra en la siguiente imagen:



Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 02-03-2015 a las 01:52:21.
Responder Con Cita