Mostrando entradas con la etiqueta delphi. Mostrar todas las entradas
Mostrando entradas con la etiqueta delphi. Mostrar todas las entradas

miércoles, 14 de febrero de 2018

Propiedad Body vacía leyendo correos o emails con delphi e Indy

El motivo es porque el correo está codificado con encapsulación MIME-encoded text. Debebemos de leer el contenido que viene en varias partes y formar una cadena única

Ejemplo delphi:
---------------------------
nota: requiere el use TIdText;

for x := 0 to TheMsg.MessageParts.Count - 1 do begin 
      if TheMsg.MessageParts.Items[x] is TIdText then 
             BodyMsg := BodyMsg+ TIdText(TheMsg.MessageParts.Items[x]).Body.Text; 
end; 




TIdText

Encapsulates a MIME-encoded text message part. TIdText = class(TIdMessagePart) Class Hierarchy
TCollectionltem TIdMessagePart TIdText [CI
Unit
IdMessage [CI TIdText Members Properties
Body
Textual content of the message part. Methods
^Assign Create
Copy the property values of an object instance. Constructor for the collection item.
^ Destroy Frees the object instance.
Legend
^virtual

Description

TIdText is a TIdMessagePart [C] descendant that encapsulates a MIME textual message part. TldAttachment [C] and TIdText are Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.
used as collection items in a TldMessageParts [C] collection.
TldText provides the Body [C] property to represent the textual content of the message part. See Also
TldMessagePart[C], Technical Support [CI
Textual content of the message part. property Body: TStrings; Description
Body is a TStrings property that represents the textual content of the MIME message part. Body will be populated with the values from a valid TStrings instance supplied in the Create [C] constructor. Body may also be updated using inherited properties and methods from TStrings, like Text and Add.
See Also
TldText.Create [C]
fuente: https://www.delphipower.xyz/indy9/tidtext.html

martes, 18 de julio de 2017

Delphi tstringlist indexof case sensitive

Desarrollando una aplicación me encontré el siguiente problema:

Cargo un objeto TStringList con caracteres. Ejemplo 'T', 'e', 's', 't'

la propiedad indexOf del objecto TStringList devuelve las coincidencias sin tener en cuenta mayúsucla y minúsculas, es decir, no es caso sensitivo.

indexOf('t') devolvería el índice: 0. Que corresponde en realidad a 'T' (mayúscula)

Para corregirlo sustituir la función indexOf por:

function TForm1.searchStringListPosition(miLista: TStringList): integer;
begin
  for Result := 0 to miLista.count - 1 do
    if AnsiCompareStr(miLista[Result], pString) = 0 then Exit;
  Result := -1;
end;

Suerte! Esta tontería me dió muchos dolores de cabeza por eso me gustaría compartir esto.

---------------------------------------
Aclaraciones:

Aclaración 1:

Esta funcionalidad ha podido ser modificada en distintas versiones de delphi según  un comenario en: http://fpc-pascal.freepascal.narkive.com/GEdB2ACG/tstringlist-indexof-case-sensitivity

Post by James Mills
Hi,
Is TStringList.indexOf case sensitive or insensitive ?
TStrings.indexOf is case insensitive, but TStringList.indexOf overrides
the TStrings.indexOf implementation accoriding to the documentation.
It is case insensitive, but this was changed recently for Delphi
compatibility.
Older versions are case sensitive. Here are the relevant log entries:

revision 1.15
date: 2003/05/29 23:13:57; author: michael; state: Exp; lines: +5 -2
fixed case insensitivity of TStrings.IndexOf
----------------------------
revision 1.14
date: 2002/12/10 21:05:44; author: michael; state: Exp; lines: +12 -5
+ IndexOfName is case insensitive
----------------------------

Michael

jueves, 13 de julio de 2017

When I select a cell in the Detail grid I get the error "Key Field not found"


0
    • I have set up a grid with a Master-Detail relationship. Each view is associated to a TClientDataSet. The detail view > MasterKeyFieldNames property has been set to match the key name of the Master View. The detail view > DetailKeyFieldNames property has been set to match the key name of the Detail View. The detail view > KeyFieldNames property has been set to match the key name of the Detail View.
      When I run the program the data displays properly at first. However, when I enter one of the fields on the Detail grid I get the error "Key Field not found". There is always one row that does not give the "Key Field not found" error, but in that row the highlighted cell displays data from another cell until another cell is selected.
0
Hello Karen,
Thank you for the message.
This error occurs because your dsDetail dataset doesn't contain the cdsKeyFieldName field.
You should assign an existent column to the TcxDBDataController.KeyFieldNames property.
For more information, please read the "Master-Detail" topic.
Thanks,
Valdemar


Fuente: https://www.devexpress.com/Support/Center/Question/Details/Q267533/when-i-select-a-cell-in-the-detail-grid-i-get-the-error-key-field-not-found

miércoles, 29 de abril de 2015

impresión raw lenta en windows 7 usando spooler de windows

Este tema me ha dado verdaderos quebraderos de cabeza y no he podido solucionarlo con información de ningún otro lugar. Me gustaría compartirlo por si alguien se encuentra con el mismo problema:

Hemos detectado que en windows 7 la impresión se vuelve muy lenta cuando llamamos reiteradamente a la función para escribir cada linea de impresión es decir algo como:

WriteRawDataToPrinter('MI_IMPRESORA', 'LINEA 1');
WriteRawDataToPrinter('MI_IMPRESORA', 'LINEA 2');
WriteRawDataToPrinter('MI_IMPRESORA', 'LINEA 3');
WriteRawDataToPrinter('MI_IMPRESORA', 'LINEA 4');
WriteRawDataToPrinter('MI_IMPRESORA', 'LINEA 5');
...

mientras que si nuestro codigo fuese algo como ...

WriteRawDataToPrinter('MI_IMPRESORA', 'LINEA 1 LINEA 2 LINEA 3 LINEA 4 LINEA 5' );

nuestra impresión no sería lenta. Se debe al hecho de 'generar un documento' para linea y su correspondiente gasto de acceso.

Esta misma forma de proceder en windows 8 no produce lentitud alguna. (Supongo que lo gestiona el spooler de windows 8)


codigo fuente de ejemplo: delphi

uses
 Winspool

------------------------------

function Tform1.WriteRawDataToPrinter(PrinterName: String; Str: String): Boolean;
var
  PrinterHandle: THandle;
  DocInfo: TDocInfo1;
  i: Integer;
  B: Byte;
  Escritos: DWORD;
begin
  Result:= FALSE;
  if OpenPrinter(PChar(PrinterName), PrinterHandle, nil) then
  try
    FillChar(DocInfo,Sizeof(DocInfo),#0);
    with DocInfo do
    begin
      pDocName:= PChar('Printer Test');
      pOutputFile:= nil;
      pDataType:= 'RAW';
    end;
    if StartDocPrinter(PrinterHandle, 1, @DocInfo) <> 0 then
    try
      if StartPagePrinter(PrinterHandle) then
      try      

        WritePrinter(PrinterHandle, PChar(Str), Length(Str), Escritos);      
        Result:= TRUE;
      finally
        EndPagePrinter(PrinterHandle);
      end;
    finally
      EndDocPrinter(PrinterHandle);
    end;
  finally
    ClosePrinter(PrinterHandle);
  end;
end;

Jesús Moreno - Ingeniero Ténico Informático - consultor Informático

Hola, soy Jesús Moreno Ingeniero Técnico Informático en sistemas por la US y propietario de éste blog. Mi trabajo en los ultimos años se ...