|
구조체에 바로 대입연산자를 사용하면 컴파일시 에러나지 않나요??
SetPatient함수처리부분에서
대입연산자 대신 memcpy함수를 써서 구조체 통채로 카피해보세요.
아니면 포인터로 전달하시던지..
구윤태 님이 쓰신 글 :
: 1.
: 프로젝트에 TCD_DataStruct.h 파일생성후
:
: [TCD_DataStruct.h]
:
: #ifndef __TCD_DataStructH__
: #define __TCD_DataStructH__
:
: typedef struct
: {
: AnsiString PatientsID;
: AnsiString ChartNo;
: AnsiString Name;
: TDateTime Birth;
: AnsiString Sex;
: AnsiString Telephone;
: AnsiString Address;
: AnsiString Remark;
: TDateTime RegistDate;
: } PATIENT;
:
: #endif
: ============================================================================
: 2. 프로젝트 공유 클래스 생성 TCD_ShareData.h
: [TCD_ShareData.h]
: #ifndef TCD_ShareDataH
: #define TCD_ShareDataH
: #include "TCD_DataStruct.h"
:
: class TCD_ShareData
: {
: private:
: PATIENT pPatient;
: public:
: TCD_ShareData();
: ~TCD_ShareData();
: void __fastcall SetPatient(PATIENT mPatient);
: PATIENT __fastcall GetPatient();
: };
: extern PACKAGE TCD_ShareData *tcdSD;
: #endif
:
:
: [TCD_ShareData.cpp]
: #pragma hdrstop
: #include <vcl.h>
: #include "TCD_ShareData.h"
: #include "Trace.h"
:
: TCD_ShareData *tcdSD;
: TCD_ShareData::TCD_ShareData()
: {
: }
: TCD_ShareData::~TCD_ShareData()
: {
: }
: void __fastcall TCD_ShareData::SetPatient(PATIENT mPatient)
: {
: pPatient = mPatient;
: }
: PATIENT __fastcall TCD_ShareData::GetPatient()
: {
: return pPatient;
: }
: #pragma package(smart_init)
: ===========================================================================================
:
: 3. Form 생성
:
:
: #ifndef TCD_PatientInputH
: #define TCD_PatientInputH
:
: #include <Classes.hpp>
: #include <Controls.hpp>
: #include <StdCtrls.hpp>
: #include <Forms.hpp>
: #include <ExtCtrls.hpp>
: #include <jpeg.hpp>
: #include <Mask.hpp>
: #include <ComCtrls.hpp>
:
:
: class Tpatientinput : public TForm
: {
: __published: // IDE-managed Components
: TImage *Image1;
: TImage *okImage;
: TImage *cancelImage;
: TMaskEdit *patientidEdit;
:
: void __fastcall okImageClick(TObject *Sender);
: void __fastcall cancelImageClick(TObject *Sender);
: public: // User declarations
: __fastcall Tpatientinput(TComponent* Owner);
: //환자 데이터 구조체 저장
: void __fastcall patientDataStore();
: };
: extern PACKAGE Tpatientinput *patientinput;
: //---------------------------------------------------------------------------
: #endif
:
:
:
: [TCD_PatientInput.cpp]
: //공유데이터
: #include <vcl.h>
: #pragma hdrstop
:
: #include "TCD_ShareData.h"
: #include "Trace.h"
:
: #pragma package(smart_init)
: #pragma resource "*.dfm"
:
: Tpatientinput *patientinput;
:
: //ok 버튼
: void __fastcall Tpatientinput::okImageClick(TObject *Sender)
: {
: //환자 정보 struct 저장
: patientDataStore();
: }
:
: void __fastcall Tpatientinput::patientDataStore()
: {
:
: //구조체에 환자 정보 저장하기
: PATIENT mPatient;
: mPatient.PatientsID= this->patientidEdit->Text;
: TRACE("mPatient=%p , mPatient.PatientsID=%s",mPatient,mPatient.PatientsID); //정상적으로 값이 표시 됩니다.
: tcdSD->SetPatient(mPatient);
: }
:
:
:
:
: ---------------------------------------------------------------------------------------------
: 문의)
: 구조체 헤더정의후 , 공유 클래스를 생성해서 구조체 개체를 만들고
: 구초체를 받아서 처리하는 루틴 만든 다음
: 새로운 폼에서 공유클래스를 이용하여 PATIENT mPatient 생성한 곳에 , 객체를 전달 하여 주는 과정입니다.
:
:
: TCD_PatientInput.cpp 소스에서 ok버튼을 실행시키면
: 구조체의 값이 저장되어 SetPatient(mPatient)를 통해서
: TCD_ShareData.cpp 소스의 SetPatient함수를 실행시키는데
:
: void __fastcall TCD_ShareData::SetPatient(PATIENT mPatient)
: {
: TRACE("mPatient=%p , mPatient.PatientsID=%s",mPatient,mPatient.PatientsID); //정상적으로 값이 표시됩니다.
: pPatient = mPatient; <-여기서 에러가 나타나는데 원인을 모르겠습니다.
: }
:
:
:
:
: 에러 내용
: Access violation at address 00432E0 in module 'TCD.exe' , Write of address 00000000
:
: 메세지가 나옵니다.
|