Can’t enter Memo by clicking the mouse

Asked

Viewed 62 times

0

In my project I have a TMemo and a TDBMemo, all of them have implemented an input and output event of the component, from a while to here began that error of not being able to enter the memo by clicking with the mouse. I do not know what is wrong because everything worked well. I will leave the Form code to analyze.

This is the Form I can’t enter with the mouse click Remembering that, Memos are not disabled and not read-only.

unit UAndamentoProcessual;

interface

uses
  Winapi.Windows, Winapi.Messages, Winapi.ShellAPI, System.SysUtils,
  System.Variants, System.Classes, Winapi.MMSystem,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtDlgs, Vcl.StdCtrls,
  Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Vcl.Mask, Vcl.Buttons, Vcl.ExtCtrls,
  Data.DB,
  frxClass, frxDBSet, IdBaseComponent, IdComponent, IdMessageClient,
  IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdSMTPBase,
  IdSMTP, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL,
  IdMessage, IdAntiFreezeBase, IdAntiFreeze, IdSASL, IdSASLUserPass,
  IdSASLLogin,
  DBAccess, Uni, MemDS, UniProvider, InterBaseUniProvider, UniDacVcl, DAScript,
  UniScript,
  ACBrBase,ACBrMail, RzEdit, RzDBEdit,
  UFuncoes, Vcl.Menus;

type
  TfrmAndamentoProcessual = class(TForm)
    pnAndamentoProcessualPesquisa: TPanel;
    pnAndamentoProcessualInclusao: TPanel;
    pnAndamentoProcessual:         TPanel;
    pnCabecalhoInclusaoAndamento:  TPanel;
    pnRodapeInclusaoAndamento:     TPanel;
    dbeDataAgenda:                 TDBEdit;
    dbeHoraAgenda:                 TDBEdit;
    dbeResponsavelAgenda:          TDBEdit;
    dbePrazoProcessual:            TDBEdit;
    dbeHoraConclusao:              TDBEdit;
    dbeDataConclusao:              TDBEdit;
    dbeHoraPrazo:                  TDBEdit;
    dbm_Observacao:                TDBMemo;
    dbm_DescricaoAgenda:           TDBMemo;
    dbmProvidencias_Descricao:     TDBMemo;
    dbcFaseProcesso:               TDBComboBox;
    chkAtoFaturavel:               TCheckBox;
    btnNovoAndamento:              TBitBtn;
    btnPublicacao:                 TBitBtn;
    btnAlterarAndamento:           TBitBtn;
    btnConsultas:                  TBitBtn;
    btnVerImprimir:                TBitBtn;
    btnCancelar:                   TBitBtn;
    btnSalvar:                     TBitBtn;
    btnNomeImagemAndamento:        TBitBtn;
    lblObservacao:                 TLabel;
    lblAgenda:                     TLabel;
    lblSolicitadoPor:              TLabel;
    lblSolicitante:                TLabel;
    lblCodAndamento:               TLabel;
    lblRestam:                     TLabel;
    lblRestamAgenda:               TLabel;
    opdNomeImagemAndamento:        TOpenPictureDialog;
    dbmObservacao2:                TMemo;
    btnExcluirAndamento:           TBitBtn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure btnNovoAndamentoClick(Sender: TObject);
    procedure btnAlterarAndamentoClick(Sender: TObject);
    procedure MudaCorEntrada(Sender: TObject);
    procedure MudaCorSaida(Sender: TObject);
    procedure opdNomeImagemAndamentoSelectionChange(Sender: TObject);
    procedure ContadorMax(Sender: TObject);
    procedure btnSalvarClick(Sender: TObject);
    procedure btnCancelarClick(Sender: TObject);
    procedure btnNomeImagemAndamentoClick(Sender: TObject);
    procedure btnExcluirAndamentoClick(Sender: TObject);
    procedure ForcaEntradaClick(Sender: TObject);
  private
    { Private declarations }
    procedure PesquisaAndamentos(ProcessoAux: string);
  public
    { Public declarations }
  end;

implementation

uses UDataModuleGeral, UDataModuleGeral2, UEntradaSistema, UTelaPrincipal,
  UManutencaoProcessos, UPublicacoes, UConsultas, USplash ,UEnviaEmailClientes,
  UDataModuleRelatorios;

{$R *.dfm}

procedure TfrmAndamentoProcessual.btnAlterarAndamentoClick(Sender: TObject);
begin
  DataModuleGeral.tbAgenda.Insert;
end;

procedure TfrmAndamentoProcessual.btnCancelarClick(Sender: TObject);
begin
  if frmSplash <> nil then frmSplash.Close;

  memDescricao_Andamento.Clear;
  dbmObservacao2.Lines.Clear;

  DataModuleGeral.tbAgenda.Cancel;
end;

procedure TfrmAndamentoProcessual.btnExcluirAndamentoClick(Sender: TObject);
var
  vSQL: String;
  iCod: Integer;
begin
  iCod := DataModuleGeral2.qryPesquisaAndamentosCODIGO_ANDAMENTO.AsInteger;

  vSQL := 'DELETE FROM ANDAMENTOS_PROCESSUAIS WHERE CODIGO_ANDAMENTO = :PCod ';

  DataModuleGeral2.qryAddEdtAnd.Close;
  DataModuleGeral2.qryAddEdtAnd.SQL.Clear;
  DataModuleGeral2.qryAddEdtAnd.SQL.Add(vSQL);
  DataModuleGeral2.qryAddEdtAnd.ParamByName('PCod').AsInteger := iCod;
  if Application.MessageBox('Deseja Realmente EXCLUIR este ANDAMENTO?','Pergunta',
                   MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON2) <> IDNO then
  begin
    try
      DataModuleGeral2.qryAddEdtAnd.ExecSQL;
    finally
      PesquisaAndamentos(vCampoProcesso);
    end;
  end else
  begin
    btnCancelarClick(Sender);
    Exit;
  end;
end;

procedure TfrmAndamentoProcessual.btnNomeImagemAndamentoClick(Sender: TObject);
begin
  opdNomeImagemAndamento.Execute;
end;

procedure TfrmAndamentoProcessual.btnNovoAndamentoClick(Sender: TObject);
begin
    DataModuleGeral.tbAgenda.Append;
end;

procedure TfrmAndamentoProcessual.btnSalvarClick(Sender: TObject);
begin

  if DataModuleGeral.tbAgenda.State in [dsInsert,dsEdit] then
  begin
    DataModuleGeral.tbAgendaCODIGO_CLIENTE.AsInteger := DataModuleGeral.tbProcessosCOD_CLIENTE.AsInteger;

    if dbmProvidencias_Descricao.Text <> '' then
    begin
      DataModuleGeral.tbAgenda.Post;
    end else
    begin
      DataModuleGeral.tbAgenda.Cancel;
    end;
  end;

  frmSplash.Close;
end;

procedure TfrmAndamentoProcessual.ForcaEntradaClick(Sender: TObject);
begin
// Isso e´o que eu estou usando para poder entrar nos memos com o Clique do Mouse
  if Sender is TMemo       then TMemo(Sender).SetFocus;
  if Sender is TDBMemo     then TDBMemo(Sender).SetFocus;
end;

procedure TfrmAndamentoProcessual.ContadorMax(Sender: TObject);
var Min, Total: Integer;
begin

  if Sender is TMemo then
  begin
    //Passando o valor minímo de caracteres do Memo para a variável Min.
    Min   := TMemo(Sender).GetTextLen;
    //Efetuando o cálculo entre o valor máximo e o mínimo.
    Total := TMemo(Sender).MaxLength - Min;
    // Testando se ainda existem caracteres disponíveis para inserir.
    if Total < 1 then
    begin
      lblRestam.Font.Color := clRed;
      lblRestam.Caption := ('Máximo!');
    end else
    begin
      lblRestam.Font.Color := clBlack;
      lblRestam.Caption := ('Restam '+IntToStr(Total));
    end;
  end;

  if Sender is TDBMemo   then
  begin
    //Passando o valor minímo de caracteres do Memo para a variável Min.
    Min   := TDBMemo(Sender).GetTextLen;
    //Efetuando o cálculo entre o valor máximo e o mínimo.
    Total := TDBMemo(Sender).MaxLength - Min;
    // Testando se ainda existem caracteres disponíveis para inserir.
    if Total < 1 then
    begin
      lblRestamAgenda.Font.Color := clRed;
      lblRestamAgenda.Caption    := ('Máximo!');
    end else
    begin
      lblRestamAgenda.Font.Color := clBlack;
      lblRestamAgenda.Caption    := ('Restam '+IntToStr(Total));
    end;
  end;
  Repaint;
end;

procedure TfrmAndamentoProcessual.MudaCorEntrada(Sender: TObject);
begin
  frmTelaPrincipal.MudaCorEntrada(Sender); <== Esse é o evento de entrada dos Memos
end;

procedure TfrmAndamentoProcessual.MudaCorSaida(Sender: TObject);
begin
  frmTelaPrincipal.MudaCorSaida(Sender);   <== Esse é o evento de Saida dos Memos 
end;

procedure TfrmAndamentoProcessual.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  btnCancelarClick(Sender);
  DataModuleGeral2.qryPesquisaAndamentos.Close;

  FreeAndNil(frmAndamentoProcessual);
end;

procedure TfrmAndamentoProcessual.FormCreate(Sender: TObject);
begin
  Application.HintHidePause := 5550;
  Position := poScreenCenter;

  DataModuleRelatorios.cdsImagens_.Close;
  DataModuleRelatorios.cdsImagens_.CreateDataSet;
  DataModuleRelatorios.cdsImagens_.Open;

  dbcUsuarioResponsavel.Items.Clear;
  DataModuleGeral.tbUsuariosConsulta.First;
end;


procedure TfrmAndamentoProcessual.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if (key=#13) and not (Copy(TControl(ActiveControl).Name,1,3)='dbm') then
    key := #0;
end;

procedure TfrmAndamentoProcessual.FormShow(Sender: TObject);
begin
  DataModuleRelatorios.cdsImagens_.Open;
  DataModuleRelatorios.cdsImagens_.EmptyDataSet;

  PesquisaAndamentos(vCampoProcesso);

  // Controle de Acesso - Inclusão
  if Copy(DataModuleGeral.qryUsuarioAtivoANDAMENTOS.AsString,2,1)  = 'S' then
    btnNovoAndamento.Enabled    := True
  else btnNovoAndamento.Enabled := False;
  // Controle de Acesso - Edição
  if Copy(DataModuleGeral.qryUsuarioAtivoANDAMENTOS.AsString,3,1)  = 'S' then
    btnAlterarAndamento.Enabled    := True
  else btnAlterarAndamento.Enabled := False;
  // Controle de Acesso - Exclusaão
  if Copy(DataModuleGeral.qryUsuarioAtivoANDAMENTOS.AsString,4,1)  = 'S' then
    btnExcluirAndamento.Enabled    := True
  else btnExcluirAndamento.Enabled := False;
  // Controle de Acesso - Publicações
  if Copy(DataModuleGeral.qryUsuarioAtivoPUBLICACOES.AsString,1,1) = 'S' then
    btnPublicacao.Enabled    := True
  else btnPublicacao.Enabled := False;
  // Controle de Acesso - Consultas
  if Copy(DataModuleGeral.qryUsuarioAtivoCONSULTAS.AsString,1,1)   = 'S' then
    btnConsultas.Enabled    := True
  else btnConsultas.Enabled := False;

  lblRestam.Caption := 'Restam '+IntToStr(dbmObservacao2.MaxLength);

  dbcFaseProcesso.DataField := vCampoFase;
  dbgPesquisaAndamentos.SetFocus;
end;

end.

The one below is what I call the form

  if frmManutencaoProcessos = Nil then
  begin
    frmManutencaoProcessos        := TfrmManutencaoProcessos.Create(self);
    frmManutencaoProcessos.Parent := frmTelaPrincipal;
  end;
  frmAndamentoProcessual.Show;

I changed the shape and Create Form I don’t know if you have any different things with respect to creation, but it’s still not working as it should when I create the form from the above mode.

Image of the Object Inspector TMemo inserir a descrição da imagem aqui

If you need any more information just ask me to post it.

  • I don’t understand Forcaentradaclick. At first it’s not necessary. Are you assigned to some event Handler? The Tabstop property of Memo is true?

  • Forcaentradaclick is a gambiarra created to enter the memo by right-clicking. because it is not entering normally.

  • has investigated the functioning of this routine? frmTelaPrincipal.MudaCorEntrada(Sender);

  • The Routine frmTelaPrincipal.MudaCorEntrada(Sender); is working properly for all fields where the routine is applied.

  • After the SetFocus, use PostMessage(TMemo(Sender).Handle, WM_SETFOCUS, 0, 0);

  • The image component name is dbmDescricao_PublicacaoIncl, but I didn’t find this reference in the code. Post as is the tab Events of TMemo specific. I noticed that in procedure TfrmAndamentoProcessual.FormShow(Sender: TObject); is manipulating the Focus dbgPesquisaAndamentos.SetFocus; if you have any Tmemo event set to FormShow then that may be the problem, for example if OnClick of TMemo is FormShow, then every time you click on Memo who will receive the focus will be the dbgPesquisaAndamentos.

  • It’s because I reset the Component’s name to dbm_Observacao because it’s too big.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.