admin管理员组文章数量:1317915
For my internship, I'm developing a simple tcl Windows-only app using C++Builder 12.
The app is used to do some simple CRUD with an interface. I'm using SQLite as a database, and also FireDAC, although that may not be relevant.
The app is divided into 2 main menus and one of them does not seem to obey the same rules.
Whenever I click on "nouvelle rallonge" (new extension) or "nouveau tube" (new tube), I call another window as well as Append()
on the right table, and after filling the required field(s) I Post()
it.
The problem is that the Append()
acts weirdly. On the rest of the app, it works as intended. But here, it gets the value of the already-existing entry in the database (displayed in the TDBGrid
) and I can modify it, but I cannot create a new entry.
I use the same window "architecture" (i.e : using TDBEdit
) and code logic as the other pages where it works perfectly fine.
Here is the code causing issues:
2nd main page :
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "menuApp.h"
#include "menuRallonges.h"
#include "datamodule.h"
#include "gestionRallonge.h"
#include "gestionTube.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFMenuRallonges *FMenuRallonges;
extern bool isEditing;
//---------------------------------------------------------------------------
__fastcall TFMenuRallonges::TFMenuRallonges(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::btRallongeClick(TObject *Sender)
{
TFRallonge *FRallonge = new TFRallonge(this);
short res = FRallonge->ShowModal();
delete FRallonge;
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::btTubeClick(TObject *Sender)
{
TFTube *FTube = new TFTube(this);
short res = FTube->ShowModal();
delete FTube;
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::FormShow(TObject *Sender)
{
DataModule1 = new TDataModule1(this);
isEditing=false;
DBGrid1->DataSource->DataSet->Refresh();
DBGrid2->DataSource->DataSet->Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::btModifRallongeClick(TObject *Sender)
{
isEditing=true;
btRallongeClick(this);
FormShow(this);
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::btModifTubeClick(TObject *Sender)
{
isEditing=true;
btTubeClick(this);
FormShow(this);
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::FormDestroy(TObject *Sender)
{
if (DataModule1 != nullptr)
{
delete DataModule1;
DataModule1 = nullptr;
}
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::FormClose(TObject *Sender, TCloseAction &Action)
{
FormDestroy(this);
}
//---------------------------------------------------------------------------
Tube page:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "datamodule.h"
#include "menuRallonges.h"
#include "gestionTube.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFTube *FTube;
extern bool isEditing;
//---------------------------------------------------------------------------
__fastcall TFTube::TFTube(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFTube::Button1Click(TObject *Sender)
{
Button1->SetFocus();
try {
DataModule1->TubevideTable->Post();
}
catch (const Exception &E) {
ShowMessage("Erreur lors de l'insertion : " + E.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TFTube::FormShow(TObject *Sender)
{
if (isEditing==true) {
// ShowMessage("editing true");
}
else
{
// ShowMessage("editing false");
// DataModule1->TubevideTable->Last();
DataModule1->TubevideTable->Append();
}
}
//---------------------------------------------------------------------------
void __fastcall TFTube::Button2Click(TObject *Sender)
{
DataModule1->TubevideTable->Cancel();
}
//---------------------------------------------------------------------------
I don't really know what is causing this, so if you have any idea please tell me.
For my internship, I'm developing a simple tcl Windows-only app using C++Builder 12.
The app is used to do some simple CRUD with an interface. I'm using SQLite as a database, and also FireDAC, although that may not be relevant.
The app is divided into 2 main menus and one of them does not seem to obey the same rules.
Whenever I click on "nouvelle rallonge" (new extension) or "nouveau tube" (new tube), I call another window as well as Append()
on the right table, and after filling the required field(s) I Post()
it.
The problem is that the Append()
acts weirdly. On the rest of the app, it works as intended. But here, it gets the value of the already-existing entry in the database (displayed in the TDBGrid
) and I can modify it, but I cannot create a new entry.
I use the same window "architecture" (i.e : using TDBEdit
) and code logic as the other pages where it works perfectly fine.
Here is the code causing issues:
2nd main page :
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "menuApp.h"
#include "menuRallonges.h"
#include "datamodule.h"
#include "gestionRallonge.h"
#include "gestionTube.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFMenuRallonges *FMenuRallonges;
extern bool isEditing;
//---------------------------------------------------------------------------
__fastcall TFMenuRallonges::TFMenuRallonges(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::btRallongeClick(TObject *Sender)
{
TFRallonge *FRallonge = new TFRallonge(this);
short res = FRallonge->ShowModal();
delete FRallonge;
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::btTubeClick(TObject *Sender)
{
TFTube *FTube = new TFTube(this);
short res = FTube->ShowModal();
delete FTube;
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::FormShow(TObject *Sender)
{
DataModule1 = new TDataModule1(this);
isEditing=false;
DBGrid1->DataSource->DataSet->Refresh();
DBGrid2->DataSource->DataSet->Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::btModifRallongeClick(TObject *Sender)
{
isEditing=true;
btRallongeClick(this);
FormShow(this);
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::btModifTubeClick(TObject *Sender)
{
isEditing=true;
btTubeClick(this);
FormShow(this);
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::FormDestroy(TObject *Sender)
{
if (DataModule1 != nullptr)
{
delete DataModule1;
DataModule1 = nullptr;
}
}
//---------------------------------------------------------------------------
void __fastcall TFMenuRallonges::FormClose(TObject *Sender, TCloseAction &Action)
{
FormDestroy(this);
}
//---------------------------------------------------------------------------
Tube page:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "datamodule.h"
#include "menuRallonges.h"
#include "gestionTube.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFTube *FTube;
extern bool isEditing;
//---------------------------------------------------------------------------
__fastcall TFTube::TFTube(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFTube::Button1Click(TObject *Sender)
{
Button1->SetFocus();
try {
DataModule1->TubevideTable->Post();
}
catch (const Exception &E) {
ShowMessage("Erreur lors de l'insertion : " + E.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TFTube::FormShow(TObject *Sender)
{
if (isEditing==true) {
// ShowMessage("editing true");
}
else
{
// ShowMessage("editing false");
// DataModule1->TubevideTable->Last();
DataModule1->TubevideTable->Append();
}
}
//---------------------------------------------------------------------------
void __fastcall TFTube::Button2Click(TObject *Sender)
{
DataModule1->TubevideTable->Cancel();
}
//---------------------------------------------------------------------------
I don't really know what is causing this, so if you have any idea please tell me.
Share Improve this question edited Jan 30 at 1:53 Remy Lebeau 598k36 gold badges503 silver badges848 bronze badges asked Jan 28 at 9:04 Alan FinitiAlan Finiti 6510 bronze badges 9 | Show 4 more comments1 Answer
Reset to default 2As @RemyLebeau
said, the creation of a new instance of 'DataModule1' is suspicious. Even if it worked fine on the other page, i don't really know why but on the other it was causing the bug this post's about. I just removed the line from the functions and now everything works fine, thanks everyone !
本文标签:
版权声明:本文标题:c++ - FireDAC Append function not creating a new record on the dataset, instead it modifies the record - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742012328a2413120.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
delphi
andpascal
? – Fred62 Commented Jan 28 at 9:18DataModule1 = new TDataModule1(this);
from another FormShow is fishy, this looks like a memory leak bug. I'm not really following this code at all. Mixing up FormShow vs FormCreate? – Lundin Commented Jan 28 at 11:35TDataModule1
on each button click? That is very suspicious. You are not destroying the previous instance, so it just hangs around in memory until the Form is destroyed. Also, yourOnDestroy
handler is redundant since you are assigningthis
as theOwner
of eachTDataModule1
instance. – Remy Lebeau Commented Jan 30 at 1:58