Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 15-01-2010
Avatar de torito
torito torito is offline
Miembro
 
Registrado: jun 2003
Ubicación: Querétaro, Mex.
Posts: 349
Poder: 21
torito Va por buen camino
lectura y escritura en un archivo de texto

Hola amigos foreros, hace rato que me habia alejado de mi delphi querido, pero ahora nuevamente sale como mi heroe, fijense que tengo un archivo de texto xml, el cual requiero ingresar para poder tomar texto en forma de lectura y en otras ocasiones de edición también, pudieran auxiliarme en esto??

de antemano muchas gracias
Responder Con Cita
  #2  
Antiguo 15-01-2010
genius genius is offline
Miembro
 
Registrado: may 2006
Posts: 38
Poder: 0
genius Va por buen camino
Creo q esto te puede servir.. aunque no lo he probado todavia ..suerte

Código Delphi [-]
 
unit uCiaXml;
interface
uses
  Forms, SysUtils, Windows, XmlIntf, XMLDoc;
type
  TXMLConfig = class
  private
    FModified: Boolean;
    FFileName: string;
    FXMLDoc: TXMLDocument;
    FBackup: Boolean;
    function GetVersion: string;
  public
    constructor Create(const FileName: string); overload;
    constructor Create; overload;
    destructor Destroy; override;
    procedure Save;
    function ReadString(const Section, Key, default: string): string;
    procedure WriteString(const Section, Key, Value: string);
    function ReadInteger(const Section, Key: string; default: Integer): Integer;
    procedure WriteInteger(const Section, Key: string; Value: Integer);
    function ReadBoolean(const Section, Key: string; default: Boolean): Boolean;
    procedure WriteBoolean(const Section, Key: string; Value: Boolean);
    property Backup: Boolean read FBackup write FBackup;
    property Version: string read GetVersion;
  end;
implementation
{ TXMLConfig }
constructor TXMLConfig.Create(const FileName: string);
begin
  inherited Create;
  FBackup         := True;
  FFileName       := FileName;
  FXMLDoc         := TXMLDocument.Create(Application);
  FXMLDoc.Options := [doNodeAutoIndent];
  if FileExists(FFileName) then
    FXMLDoc.LoadFromFile(FFileName)
  else 
  begin
    FXMLDoc.Active := True;
    FXMLDoc.AddChild('Configuration');
  end;
end;
constructor TXMLConfig.Create;
begin
  Create(ChangeFileExt(Application.Exename, '_cfg.xml'));
end;
destructor TXMLConfig.Destroy;
begin
  Save;
  FXMLDoc.Destroy;
  inherited;
end;
function TXMLConfig.GetVersion: string;
begin
  Result := '1.00';
end;
function TXMLConfig.ReadBoolean(const Section, Key: string; default: Boolean): Boolean;
begin
  Result := Boolean(ReadInteger(Section, Key, Integer(default)));
end;
function TXMLConfig.ReadInteger(const Section, Key: string; default: Integer): Integer;
begin
  Result := StrToInt(ReadString(Section, Key, IntToStr(default)));
end;
function TXMLConfig.ReadString(const Section, Key, default: string): string;
var
  Node: IXMLNode;
begin
  Node := FXMLDoc.DocumentElement.ChildNodes.FindNode(Section);
  if Assigned(Node) and Node.HasAttribute(Key) then
    Result := Node.Attributes[Key]
  else
    Result := default;
end;
procedure TXMLConfig.Save;
begin
  if not FModified then
    Exit;
  if FBackup then
    CopyFile(PChar(FFileName), PChar(FFileName + '.bak'), False);
  FXMLDoc.SaveToFile(FFileName);
  FModified := False;
end;
procedure TXMLConfig.WriteBoolean(const Section, Key: string; Value: Boolean);
begin
  WriteInteger(Section, Key, Integer(Value));
end;
procedure TXMLConfig.WriteInteger(const Section, Key: string; Value: Integer);
begin
  WriteString(Section, Key, IntToStr(Value));
end;
procedure TXMLConfig.WriteString(const Section, Key, Value: string);
var
  Node: IXMLNode;
begin
  if ReadString(Section, Key, '') = Value then
    Exit;
  Node := FXMLDoc.DocumentElement.ChildNodes.FindNode(Section);
  if not Assigned(Node) then
    Node := FXMLDoc.DocumentElement.AddChild(Section);
  Node.Attributes[Key] := Value;
  FModified := True;
end;
end.
Responder Con Cita
  #3  
Antiguo 15-01-2010
Avatar de torito
torito torito is offline
Miembro
 
Registrado: jun 2003
Ubicación: Querétaro, Mex.
Posts: 349
Poder: 21
torito Va por buen camino
Muchas gracias, voy a revisarlo.
Responder Con Cita
  #4  
Antiguo 16-01-2010
Jopeh Jopeh is offline
Registrado
 
Registrado: ene 2010
Posts: 2
Poder: 0
Jopeh Va por buen camino
Necesito ayuda para un proyecto

Hice un Editor de Texto con un control sacado de Torry.net para ocultar la app en la bandeja de sistema y está funcionando muy bien. Pero se me complica el algoritmo de búsqueda de una cadena de texto en el control Memo. ¿Podrían ayudarme con eso?
Desde ya, muchas gracias.
Responder Con Cita
  #5  
Antiguo 18-01-2010
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.271
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Cita:
Empezado por Jopeh Ver Mensaje
Hice un Editor de Texto....
Por favor Joseh, revisa la Guía de estilo de los foros y no mezcles temas.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Lectura de teclado sin campo de texto floren PHP 9 22-09-2004 09:25:22
Lectura Escritura de puertos daseretto Varios 4 19-04-2004 16:24:27
Error en lectura logs texto alejandrowa Varios 6 03-06-2003 20:31:28
Escritura de archivo dbf ramiretor Conexión con bases de datos 2 26-05-2003 23:20:24
Ejemplo de Lectura/escritura en MS Excel Yarri Conexión con bases de datos 3 14-05-2003 16:06:44


La franja horaria es GMT +2. Ahora son las 17:29:28.


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
Copyright 1996-2007 Club Delphi