Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Stringgrid Manipulation

feddyfeddy Member Posts: 1
Hi.. I need help in stringgrid manipulation, I use stringgrid as array. And I use this array for calculation process. there is some calculation process in every step (in this cased step is called chromosom).. The problem is number-number in stringgrid always show for the last step (chromosom), the previous step (chromosom always) replace by the next step (chromosom) until the last step (chromosom). So the stringgrid always show number-number for the last step. However I want to show all step (chromosom) in the stringgrid.... So what must I do to fix this.. Ok thanks. Your help is very useful for me. this is my code
//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "Uskripsi.h"
#include
#include
#include
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

/*Fungsi untuk input jumlah data dan jumlah atribut data*/
void __fastcall TForm1::btnOkClick(TObject *Sender)
{
gbInput->Visible=false;
gbData->Visible=true;
gbGA ->Visible=false;
InputData();

}
//---------------------------------------------------------------------------
/*Fungsi untuk kembali ke input jumlah data dan jumlah atribut data*/
void __fastcall TForm1::btnBackInpClick(TObject *Sender)
{
gbInput->Visible=true;
gbData->Visible=false;
gbGA->Visible=false;
}
//---------------------------------------------------------------------------
/*Fungsi untuk lanjut ke proses GA*/
void __fastcall TForm1::btnNextClick(TObject *Sender)
{
/*{
sgData->Cells[0][i]="Data"+String(i);
} */
//ShowMessage("isi data"+String(sgData->Cells[j][i]));
gbInput->Visible=false;
gbData->Visible=false;
gbGA->Visible=true;
}
//---------------------------------------------------------------------------
/*Fungsi untuk kembali ke Data*/
void __fastcall TForm1::btnBackDtClick(TObject *Sender)
{
gbInput->Visible=false;
gbData->Visible=true;
gbGA->Visible=false;
}
//---------------------------------------------------------------------------
/* Fungsi untuk memberikan identifikasi awal New Problem */
void __fastcall TForm1::InputData()
{
jumData=StrToInt(txtData->Text);
jumAtribut=StrToInt(txtAtribut->Text);
sgData->ColCount=jumAtribut+1;
sgData->RowCount=jumData+1;
for (i=1;iColCount;i++)
{
sgData->Cells[i][0]="X"+String(i);
}
for (i=1;iRowCount;i++)
{
sgData->Cells[0][i]="Data"+String(i);
}

}
/* Fungsi menyimpan data yang telah diisikan */
void __fastcall TForm1::btnSaveClick(TObject *Sender)
{
if (SD->Execute())
{
std::auto_ptr SaveStrings(new TStringList());
SaveStrings->Add(txtData->Text);
SaveStrings->Add(txtAtribut->Text);

for (i=1;iRowCount;i++)
{
for (j=1;jColCount;j++)
{
SaveStrings->Add(sgData->Cells[j][i]);
}
}

SaveStrings->SaveToFile(SD->FileName);
}
}
//---------------------------------------------------------------------------
/* Fungsi memanggil data yang telah disimpan sebelumnya */
void __fastcall TForm1::btnOpenClick(TObject *Sender)
{

if (OD->Execute())
{
std::auto_ptr LoadStrings(new TStringList());
LoadStrings->LoadFromFile(OD->FileName);
txtData->Text = LoadStrings->Strings[0];
txtAtribut->Text = LoadStrings->Strings[1];
int index;
btnOk->Click();
index =2;
for (i=1;iRowCount;i++)
{
for (j=1;jColCount;j++)
{
sgData->Cells[j][i] = LoadStrings->Strings[index++];
}
}
}

}

//---------------------------------------------------------------------------


void __fastcall TForm1::btnGAClick(TObject *Sender)
{
klmpk=StrToInt(txtKlmpk->Text);
jumKrom=StrToInt(txtKromAwl->Text);
if (klmpk>jumData)ShowMessage("Tolong inputnya, dibenarkan");
else
generateAwal();
}
void __fastcall TForm1::generateAwal()
{
sgKrom->ColCount=jumData;
sgKrom->RowCount=jumKrom;

int rand,cek;

for(i=0;iCells[j][i]=NULL;
}
}
for (i=0;iCells[j][i]=rand;
}
else
{
ulang:
cek=0;
rand=random(klmpk)+1;
for (k=0;kCells[k][i]==rand)cek++;
}
if (cek==0)
{
sgKrom->Cells[j][i]=rand;
}
else goto ulang;

}
}

}
for (i=0;iCells[j][i]==0)
{
sgKrom->Cells[j][i]=random(klmpk)+1;
}
}
}
hitungfitness();




//ShowMessage(String(rand));
}
/* Fungsi untuk menghitung nilai fitness */
void __fastcall TForm1::hitungfitness()
{
int a;
int b;
for (i=0;iCells[j][i]==k)
{
jum++;
if (bRowCount=klmpk;
sgFitnes->ColCount=jumAtribut*b;

for (i=0;iCells[j][i]=NULL;
}
}

for (i=0;iCells[j2][i2]=NULL;
}
}
for (k=1;k<=klmpk;k++)
{
a=0;
for (int j=0;j<jumData;j++)
{
if(StrToInt(sgKrom->Cells[j][i])==k)
{
int c;
for (c=1;c<=jumAtribut;c++)
{
if (a<sgFitnes->ColCount)
{
sgFitnes->Cells[a][k-1]=sgData->Cells[c][j+1];
a++;

}
}
}
}
}
/* ofstream tulis;

tulis.open("D:coba.txt",ios::app);
tulis << "SG Fitness Kromosom 1" << endl;
for (int p;p<sgFitnes->RowCount;i++)
{
for (int q;qColCount;q++)
{
tulis << sgFitnes->Cells[q][p] <<" ";
}
tulis <<endl;
}
tulis.close();
ShowMessage("Langkah "+String(i)+" Selesai") ;
}*/
sgMean->ColCount=jumAtribut;
sgMean->RowCount=klmpk;

for (int i=0;iCells[j][i]);
while (adaCells[k][i]);
if (jum==jum+StrToInt(sgFitnes->Cells[k][i]))
break;
ada++;
Memo1->Lines->Add("k="+String(k));
Memo1->Lines->Add("jum="+String(jum));
Memo1->Lines->Add("ada="+String(ada));
}
rata2=jum/(ada*1.0);
sgMean->Cells[j][i]=rata2;
}
}
sgFitnes1->RowCount=sgFitnes->RowCount;
sgFitnes1->ColCount=sgFitnes->ColCount;

for(int i=0;iCells[j][i]=NULL;
}
}
for (int i=0;iCells[k][i]-sgMean->Cells[j][i]);
sgFitnes1->Cells[k][i]=x*x;
while (adaCells[k][i]-sgMean->Cells[j][i]);
if (sgFitnes->Cells[k][i]==0)
break;
sgFitnes1->Cells[k][i]=x*x;
ada++;
}

}
}


sgSscp->ColCount=jumAtribut;
sgSscp->RowCount=klmpk;

for (int i=0;iCells[j][i]);
while (adaCells[k][i]);
ada++;
}
sscp=jum;
sgSscp->Cells[j][i]=sscp;
}
}

sgSscp1->ColCount=jumAtribut;

for (int i=0;iColCount;i++)//Untuk menghitung total SSCP
{
float sscp=0;
for (int j=0;jRowCount;j++)
{
sscp=sscp+StrToFloat(sgSscp->Cells[i][j]);
}
sgSscp1->Cells[i][0]=sscp;
ShowMessage("sscp total"+String(sscp));
}

for (int i=0;iRowCount;i++)//Untuk Menghitung trace
{
float trace=0;
for (j=0;jColCount;j++)
{
trace=trace+StrToFloat(sgSscp1->Cells[j][i]);
}
sgTrace->Cells[0][i]=trace;
ShowMessage("tracenya"+String(trace));
}

ShowMessage("Langkah "+String(i)+" Selesai");
}

}

//---------------------------------------------------------------------------








void __fastcall TForm1::Exit1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------












Comments

Sign In or Register to comment.