Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
and suffix with
//---------------------------------------------------------------------------
#include <vcl.h>
#include <string.h>
#pragma hdrstop
//////////#include "CompilerTest.h"
// For convience the *.h file has been inserted directly below.
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *StartTest;
void __fastcall StartTest_Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
void TestMe(int Index, String Str, int* pOcc);
//---------------------------------------------------------------------
// This program demonstrates 2 problems that may very well be related.
//---------------------------------------------------------------------
//---------------------------------------------------------------------
// Begin problem #1
//---------------------------------------------------------------------
const String gksExeDir = "C:\\Program Files\\xxx\\Exe";
const String gksIniDir = "C:\\Program Files\\xxx\\Ini";
const String gksFileCompare_LDFN = "FileCompare_LastDir.Ini";
const String gksFileCompare_LFFN = "FileCompare_LastFiles.Ini";
//-----------------------------------------------------------------------------
// Going back to the old "constructor" method of initialization DOES work.
// (work == the two LHS constants end up with distinct values)
const String gksFileCompare_LastDir ( gksIniDir + "\\" + gksFileCompare_LDFN);
const String gksFileCompare_LastFiles ( gksIniDir + "\\" + gksFileCompare_LFFN);
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// These lines do NOT work. It compiles with no warning nor error, but as
// it turns out, both LHS values are identical. Checking of the addresses of
// both LHS variables shows that both have the same address.
const String Bad_gksFileCompare_LastDir = gksIniDir + "\\" + gksFileCompare_LDFN;
const String Bad_gksFileCompare_LastFiles = gksIniDir + "\\" + gksFileCompare_LFFN;
//-----------------------------------------------------------------------------
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
int i;
int AddressLHS1, AddressLHS2;
int AddressLHS1_Bad, AddressLHS2_Bad;
AddressLHS1 = (int)&gksFileCompare_LastFiles;
AddressLHS2 = (int)&gksFileCompare_LastDir;
AddressLHS1_Bad = (int)&Bad_gksFileCompare_LastFiles;
AddressLHS2_Bad = (int)&Bad_gksFileCompare_LastDir;
//-----------------------------------------------------------------------------
// Put a BREAK at the following line and observe that both gksFileCompare_LastDir
// and gksFileCompare_LastFiles are IDENTICAL in value, and AddressLHS1_Bad
// and AddressLHS2_Bad are IDENTICAL. Whereas, AddressLHS1 and AddressLHS2 are
// distinct.
//-----------------------------------------------------------------------------
i = 1;
//---------------------------------------------------------------------
// End problem #1
//---------------------------------------------------------------------
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StartTest_Click(TObject *Sender)
{
int Index, Occ;
int* pOcc = &Occ;
String Str;
TestMe(Index, Str , pOcc);
int i = 1;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------
// Begin problem #2
//---------------------------------------------------------------------
void TestMe(int Index, String Str, int* pOcc)
{
int i;
String sJunk;
String OrigReplaceStr;
String ReplaceStr;
ReplaceStr = "Valid Text";
OrigReplaceStr = ReplaceStr;
ReplaceStr[1] = 'X';
//---------------------------------------------------------------------
// Put a BREAK at the following line and observe that both OrigReplaceStr and
// ReplaceStr have an "X" as the first character. THAT'S BAD.
//---------------------------------------------------------------------
i = 1;
// D A N G E R ---- W A R N I N G --- SPASTIC COMPILER
// If the seemingly stupid code below is not done, then the compiler apparently
// sets the pointer for OrigReplaceStr to be equal to that of ReplaceStr.
// With the result that when ReplaceStr[n] is executed, the value of
// OrigReplaceStr is ALSO CHANGED.
{ int Len = ReplaceStr.Length();
sJunk = "abc";
OrigReplaceStr = ReplaceStr + sJunk;
OrigReplaceStr = OrigReplaceStr.SubString(1, Len);
ReplaceStr[1] = 'Q';
// Put a BREAK at the following line and observe that
// OrigReplaceStr still = "Xalid Text", but
// ReplaceStr now = "Qalid Text". , as it should.
i = 1;
}
//---------------------------------------------------------------------
// End problem #2
//---------------------------------------------------------------------
}