• Hello,
    I'm writing a routine auto-text. I created a table for the User type text.
    in another form when he enters a shortcut, eg "1" and enter key, do I find the text with the code and add 1 at the current cursor position using the function: InputString. The problem is that the text appears without the original formatting, totally mangled. Julian, can you help me?

    My code

    OnKeyPress Event

    if (Key = #13) then
    begin
    Current_Line := edtTEXTOLAUDO.CPPosition;
    edtTEXTOLAUDO.Setfocus;
    // Begin search text
    tmpKey := edtTEXTOLAUDO.CPWord;
    //
    try
    try
    MainForm.wpTexto.Clear;
    MainForm.wpTexto.AsString := RetornaAutoTexto(Text_ID, tmpKey);
    MainForm.wpTexto.SelectAll;
    MainForm.wpTexto.Font := edtTEXTOLAUDO.Font;
    //
    finally
    if ( MainForm.wpTexto.AsString <> '' ) then
    begin
    edtTEXTOLAUDO.CPWord := '';
    edtTEXTOLAUDO.InputString(MainForm.wpTexto..RTF.AsString);
    end;
    end;
    except
    on E: Exception do
    begin
    if ( ParamStr(1) = '-debug' ) then
    InfoMessage('DlgLaudar Line 829: ' + E.Message);
    end;
    end;


    function RetornaAutoTexto(AExame: Integer; AValor: string): string;

    var
    q: TIBQuery;
    c: TCursor;
    begin
    Result := '';
    if (AExame = 0) or (AValor = '') then
    Exit;
    c := SaveScreenCursor;
    q := NewQuery;
    q.SQL.Clear;
    q.SQL.Add('SELECT ET.TEX_ID, TE.TEXTO AS TEXTO');
    q.SQL.Add(' FROM EXAMETEXTO ET, TEXTOS TE');
    q.SQL.Add(' WHERE ET.EXA_ID = :EXA_ID');
    q.SQL.Add(' AND ET.APELIDO = :APELIDO');
    q.SQL.Add(' AND TE.TEX_ID = ET.TEX_ID');
    // parâmetros
    q.ParamByName('EXA_ID').AsInteger := AExame;
    q.ParamByName('APELIDO').AsString := UpperCase(AValor);
    try
    q.Open;
    if not q.IsEmpty then
    Result := q.FieldByName('TEXTO').AsString;
    except
    //..
    end;
    q.Close;
    q.Free;
    RestoreScreenCursor(c);
    end;