Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in files and then merging with another file. 1

Status
Not open for further replies.

b0xx

Programmer
Nov 13, 2007
19
US
I am working on a project where I have 2 files, a .db file, and a .txt file. The DB file contains a 'tag' and a 'value'. The txt file contains a tag, and other info, like location, units, etc so you know what the value means. I need to read in the txt file and the db file, and display them so that everything from the txt file is associated with the db file. I am pretty new to borland. Right now I have the db file displayed, but dont know how to get the text file read-in and then merged with the db file. Any tips?
 
Can you resize the fixed column width in tstringgrid?
Look at DefaultColWidth.

I tried to make some buttons that would go through the records
I've never done that. I think they did something like that in one of the articles I mentioned above.



James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
I got the buttons to work, they do what they are supposed to, but the pictures just dont show. Dont worry about it though, no biggie.

I wrote a function to clear exactly like you did. I made a menu option that is supposed to call it, but nothing happens.
What exactly is the function header supposed to look like? Is there anything else to pass besides the grid itself?

Also, the code you mentioned a few posts up, where exactly is that supposed to go? Be specific if you can about the headers because that has really be screwing me up.
 
What exactly is the function header supposed to look like?
Post the function here so I can get an idea of what you are doing.

The code I for going through the DB grid can go just about anywhere. You can write a function then call that function when you press a button.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
void StringGridClear(TStringGrid *StringGrid1)
{
...
}

Then I have this...

void __fastcall TfrmMain::sortLocExecute(TObject *Sender)
{
StringGridClear(StringGrid1);
}

Just to test, but it doesnt do anything.

I dont know if this will matter or not, but at the moment I read in and display the textfile inside the StringGrid1Click method, so nothing shows up until I click the grid when I run the program. Thats where it took me when I double clicked on the grid when I was coding. I figured it would be easy enough to move some stuff later to make it appear instantly, but it may be affecting my clear method.
 
if you dont mind, go ahead and let me know if you expect something to be your last post for the day, so I am not waiting around.
 
Also, It looks like a writeGrid function would be helpful. Something that would just rewrite what I have in my array in the order it is in to the grid. I could just call the write after I sort. As I have it now, I read in the file and write it to the grid (and the screen) in ths StringGrid1Click function. Do I need to do anything special with parameters, or just pass the grid and the array?

I sure wish you could edit your posts...
 
Looks like my array is going to need to be seen globally now. Before it only exsisted inside the StringGrid1Click function. Where do declare something like that so it can be seen by everything... just up by where I have my class defintion and function prototypes?

I dont see a main() function like you normally would, or I would just stick it there.
 
Sorry, I had already shutdown my computer for the night before I got your emails. Then this morning, I couldn't get onto the site.

Since you are working with Windows, there is not a main() function per se. Instead, you will have a WinMain() function. Normally, when you create a project in Borland, the compiler creates several files. One of the *.cpp files will be the name of your project. For example, frmMain.cpp. If you open this file up you will see something like this:
Code:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", frmMain);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    try
    {
         Application->Initialize();
         Application->Title = "Form Name";
         Application->CreateForm(__classid(frmMain), &frmMain);
         Application->Run();
    }
    catch (Exception &exception)
    {
         Application->ShowException(&exception);
    }
    catch (...)
    {
         try
         {
             throw Exception("");
         }
         catch (Exception &exception)
         {
             Application->ShowException(&exception);
         }
    }
    return 0;
}
//---------------------------------------------------------------------------
This is the main c++ file. Rarely do you need to change this. The only time I've ever changed it was to set up mutexes.

The program that you change are normally named Unit1.cpp and Unit1.h (unless you rename them when you save the project). I always rename them but it isn't necessary.

In your Unit1.h are the declarations that the header uses. Essentially, Unit1 is a class declaration. When I create a function in my C++ file, I put its declaration in the unit's *.h file. In this file, there will be a private and public section for the class. I always put my functions' declarations in here, usually in the private section.
Code:
private:	// User declarations
    void StringGridClear(TStringGrid *StringGrid1);

public:		// User declarations
    __fastcall TFrmMain(TComponent* Owner);

Also, in the body of the C++ file, I would change
Code:
void StringGridClear(TStringGrid *StringGrid1)
{
...}
to
Code:
void TFrmMain::StringGridClear(TStringGrid *StringGrid1)
{
...
}

See if that helps.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
This is my last update until Friday.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
This has been resolved. I would like to thank James for all hit help. He was invaluable.
 
Glad I could help.


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top