Problem accessing an object from one form to another in delphi

2

I have a problem with two classes in delphi, I have them in the following way

unit uModuloDatos;

interface
uses
FloguinUsuario;
.
.
.
.
procedure TModuloDatos.DataModuleCreate(Sender: TObject);
var
ConEnc : String;
pedro : TFormLoguinUsuario;
begin
iniconfig:=TConfigIni.Create(ExtractFilePath(ParamStr(0)) + INIFILENAME);
try
ConexionServidorDS_Datos.Connected:=False;
ConexionServidorDS_Datos.Params.Values['HostName'] := iniconfig.Servidor;
ConexionServidorDS_Datos.Params.Values['port'] := iniconfig.PuertoDatos;
ConexionServidorDS_Datos.Params.Values['DSAuthenticationUser']:= 
iniconfig.Usuario;
// Encriptar la contraseña introducida con SHA1
 conenc:='';

**conEnc:=FormLoguinUsuario.EContrasena.Text;** 
if iniconfig.Password<>ConEnc then
begin
  conEnc:=iniconfig.Password; // 40 caracteres
  iniconfig.Save;
 end else
 begin
   conenc:=CalcHash2(ConEnc,haSHA1);
   iniconfig.Password:=ConEnc;
 end;
 // iniconfig.Password:=ConEnc;
 ConexionServidorDS_Datos.Params.Values['DSAuthenticationPassword']:= ConEnc;
 ConexionServidorDS_Datos.Connected:=True;
 ConexionServidorDS_Datos.Open;
 iniconfig.Save;

except
 on E: Exception do begin
  MessageDlg('No se puede establecer la conexión con el servicio de 
 datos'+#10#13+
          'Revise los parámetros de conexión',TMsgDlgType.mtError,
 [TMsgDlgBtn.mbOK],0);
  Application.Terminate;
 end;
end;
end;

And another class as follows:      unit FLoguinUser;

 interface

 uses
System.SysUtils, System.Types, System.UITypes, System.Classes, 
System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Objects, FMX.Edit, Data.DB, Datasnap.DBClient,IdStack,Data.DBXCommon ;

procedure TFormLoguinUsuario.BtnAceptarClick(Sender: TObject);
var
conEnc : String;
iniconfig : TConfigIni;
begin
iniconfig:=TConfigIni.Create(ExtractFilePath(ParamStr(0)) + 'config.ini');
// Validar formato de datos introducidos
iniconfig.Servidor:=EServidor.Text;
iniconfig.PuertoDatos:=EPuerto.Text;
iniconfig.Usuario:=EUsuario.Text;
iniconfig.Password:=EContrasena.Text;
if CBRecordarClave.IsChecked then
begin
EContrasena.Text:=iniconfig.Password;
end else
begin
EContrasena.Text:='';
end;

My problem is that it gives me an INACCESSIBLE VALUE error in the bold line, I try to access the value of the password edit but it always gives me   INACCESSIBLE VALUE and I do not understand why the truth, I have everything in public, obviously you also use them ... I do not know why I can not access the text of the object.

Greetings!

    
asked by Roman345 31.01.2018 в 08:26
source

2 answers

0

In the unit uModuloDatos add in the clause uses to the name of the unit where the variable FormLoguinUsuario is defined; it will work if and only if EContrasena is some object, component or property defined as public, so that it is visible from other units of your Delphi project.

    
answered by 24.07.2018 в 23:15
0

The message "Inaccessible Value" is not an error that is occurring within your program, but a message that you are seeing inside the Delphi application debugger (debugger).

It means that the variable you are evaluating or following does not have a representation in memory at that moment and therefore has no "value", or its value is inaccessible .

This is usually due to the combination of linker and optimizer actions, which are part of the compiler.

These algorithms, which apply to your code during compilation, aim to generate optimal code by making the machine language representation of your algorithms in Pascal.

One of the effects that both have (in different cases and different moments), is that there are symbols that do not have representation in memory during certain moments of the program, even when they are within the (apparent) context of execution in the representation in Pascal, they are actually out of context (not declared or inaccessible for some other reason) in the binary code.

It sounds very tangled, but it's easy to prove, and better that I'll try.

Look at this snippet of code:

procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
begin
  ShowMessage('Hola');
  s := 'Hola2';
  ShowMessage(s);
  s := 'Hola3';
  ShowMessage('Otro hola');
end;

By putting a breakpoint in the begin of the routine, executing and clicking on the button, when the Delphi IDE is launched with the debugger loaded, I can see this message "Inaccessible value" in the Variable Inspector , in the watch and also in the tooltip that appears if I pass the mouse pointer over the name of the variable.

This is because that variable is not yet in use, and therefore, in machine code representation, it has not been "declared" (and therefore inaccessible).

Then, I advance the execution step by step, and once the first assignment of a value occurs, everything seems normal , and it will be while the variable is "in real use" within the program.

As soon as the variable is no longer used, the optimizer is likely to take it out of context and thus be inaccessible again.

    
answered by 01.08.2018 в 21:28