Page 1 of 1

Problem creating table at run time

Posted: Fri 26 Oct 2012 18:38
by sandy771
I have the following code snippet. When I step through the code at the last line I get an exception EDatabase error "TYpe mismatch for field 'key', expecting: unknown actual:Memo

Tab is a TUniTable

Any ideas what i am doing wrong


Code: Select all

	TField *f;
	Tab->SQL->Clear();
	Tab->SQL->Add("CREATE TABLE test (key TEXT NOT NULL PRIMARY KEY, value TEXT)");
	Tab->Execute();

	f = new TField(NULL);
	f->FieldName = "key";
	f->SetFieldType(ftString);
	Tab->Fields->Add(f);
	f = new TField(NULL);
	f->FieldName = "value";
	f->SetFieldType(ftString);
	Tab->Fields->Add(f);

	Tab->TableName = "test";

	Tab->Active = true;

Re: Problem creating table at run time

Posted: Mon 29 Oct 2012 10:27
by AlexP
Hello,

The SetFieldType method in the TField class is a "faceplate", i.e. it is virtual and doesn't perform any actions, this method is redefined in descendants. Therefore you should use the classes corresponding your field type in your code - TMemoField instead of TField