Fórum Erro de Access Violation #252111
26/09/2004
0
Por favor, me ajudem. Tenho o seguinte código de definições de tipos:
Quando eu vou utilizar esses tipos no código abaixo o programa gera um erro de Access Violation.
Alguém sabe onde está o erro deste código?
type Long = Longint; ERRORMSG=record bErrClass,bErrCode,bAddHi,bAddLo:byte; end; PService = ^TService; TService = record bService, fShortCnf: byte; wTargetAddress: Word; wIndex, wDataLength: Word; bTeleType: byte; Data: record lDate: Long; abData: array[0..9] of Byte; end; awPA, awPE: array[0..9] of Word; fpbDataPointer: PChar; abReserve: array[0..9] of Byte; Error: ERRORMSG; end;
Quando eu vou utilizar esses tipos no código abaixo o programa gera um erro de Access Violation.
var Servico:PService; begin Servico.bService:=3; Servico.fShortCnf:=0; Servico.wTargetAddress:=0; Servico.wIndex:=11005; Servico.wDataLength:=0; Servico.bTeleType:=$80; Servico.Data.lDate:=3; end;
Alguém sabe onde está o erro deste código?
Dan.sm
Curtir tópico
+ 0
Responder
Posts
26/09/2004
Alysson
Axei 2 erros......
1: a definição do PService = ^TService tem q ficar depois da definicao Tservice.. assim:
----------------------------------------------------------------------
e a outra:
1: a definição do PService = ^TService tem q ficar depois da definicao Tservice.. assim:
type Long = Longint; ERRORMSG=record bErrClass,bErrCode,bAddHi,bAddLo:byte; end; TService = record bService, fShortCnf: byte; wTargetAddress: Word; wIndex, wDataLength: Word; bTeleType: byte; Data: record lDate: Long; abData: array[0..9] of Byte; end; awPA, awPE: array[0..9] of Word; fpbDataPointer: PChar; abReserve: array[0..9] of Byte; Error: ERRORMSG; end; PService = ^TService;
e a outra:
var
Servico:PService;
begin
{kra por ser um Pointer, vc tem q reservar um espaco na memória ram com isso:}
GetMem(Servico,Sizeof(TService));
{se der erro, tente GetMem(Servico,Sizeof(PService));.
se continuar dando erro, tente GetMem(Servico);
to falando q se der erro, pq n to com delphi aberto...
}
Servico.bService:=3;
Servico.fShortCnf:=0;
Servico.wTargetAddress:=0;
Servico.wIndex:=11005;
Servico.wDataLength:=0;
Servico.bTeleType:=$80;
Servico.Data.lDate:=3;
end;
Responder
Gostei + 0
26/09/2004
Dan.sm
Valeu, o problema estava mesmo na hora de eu atribuir um valor sem ter alocado memória. :wink:
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)