Home » U++ Library support » U++ Library : Other (not classified elsewhere) » bug in DbfView example
|
Re: bug in DbfView example [message #10801 is a reply to message #10778] |
Mon, 30 July 2007 05:23 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
I found out some more problems...
1)
while(dbf.Fetch()) {
Vector<Value> v;
for(int i = 0; i < min(4, dbf.GetFieldCount()); i++)
v.Add(dbf[i]);
table.Add(v);
}
Does add all record to table, but it does skip over deleted rows, what does cause inconsistency with later
void DbfView::EnterRow()
{
row.Clear();
if(!dbf.Fetch(table.GetCursor()))
return;
So you get wrong detailed view in such case, and whole index will be moved by -1 to -n (number of deleted rows).
Quick fix:
if(!dbf.Open(~fs))
Exclamation("Can't open input file");
for(int i = 0; i < min(4, dbf.GetFieldCount()); i++)
table.AddColumn(FormatField(dbf.GetField(i)));
for (int ri = 0; ri < dbf.GetRowCount(); ++ri ) {
Vector<Value> v;
if(!dbf.Fetch(ri)) v.Add("DELETED");
else for(int i = 0; i < min(4, dbf.GetFieldCount()); i++) v.Add(dbf[i]);
table.Add(v);
}
edit: ARGH, I used the local "i" two times... not very good programming practice... ... so I changed it to "ri".
This will add also deleted rows to the main table, so the cursor is always right than.
2)
I'm unable to show correct czech characters no matter what charset I try. (in my desperation I tried all 26 of them)
My code to convert looks like this (in void DbfView::EnterRow):
...
for(int i = 0; i < dbf.GetFieldCount(); i++) {
Value val = dbf[i];
if ( val.GetType() == STRING_V ) {
String valtxt = val.ToString();
//WString valwtxt = ToUnicode(valtxt, CHARSET_WIN1250);
WString valwtxt = ToUnicode(valtxt, dbf.GetCharset() );
row.Add(FormatField(dbf.GetField(i)), valwtxt);
} else {
row.Add(FormatField(dbf.GetField(i)), val);
}
U++ 2007.1, Kubuntu 6.10
Charset for IDE: UTF-8
Charset for application: tried UTF-8, win1250, ISO8859_2, CP852, MJK
No luck so far... I will try it later on windows, maybe there some charset will work??
@Mirek: is it possible the result on windows will be different?
(P.S. I'm trying to do my first commercial project in U++, something very small, ugly, and it should work with DBF files from FoxPro ... the final application will be for Windows, but so far I'm developing just some base and toying around, so I'm staying in my main system so far ... that's the reason why I'm so into this example, I really must be sure I understand the DBF plugin enough )
[Updated on: Mon, 30 July 2007 05:25] Report message to a moderator
|
|
|
|
|
Re: bug in DbfView example [message #11076 is a reply to message #10804] |
Sat, 18 August 2007 11:05 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
mrjt wrote on Mon, 30 July 2007 06:05 | "name", "filter" is the correct format. For example:
fs.Type("Text Files", "*.txt");
Although ".txt" will also work.
|
Sorry about messed example...
This should solve some of problems, please test:
#include <CtrlLib/CtrlLib.h>
#include <plugin/dbf/dbf.h>
using namespace Upp;
struct DbfView : public TopWindow {
Splitter s;
ArrayCtrl table;
ArrayCtrl row;
DbfStream dbf;
void EnterRow();
void Perform();
typedef DbfView CLASSNAME;
DbfView();
};
String FormatField(const DbfStream::Field& f)
{
return f.name + Format(" (%c%d)", f.type, f.width);
}
void DbfView::EnterRow()
{
row.Clear();
if(!dbf.Fetch(table.GetKey()))
return;
for(int i = 0; i < dbf.GetFieldCount(); i++)
row.Add(FormatField(dbf.GetField(i)), dbf[i]);
}
void DbfView::Perform()
{
FileSel fs;
LoadFromFile(fs);
fs.AllFilesType();
fs.Type("dbf", "*.dbf");
if(!fs.ExecuteOpen("DBF..")) return;
StoreToFile(fs);
if(!dbf.Open(~fs))
Exclamation("Can't open input file");
table.AddKey();
for(int i = 0; i < min(4, dbf.GetFieldCount()); i++)
table.AddColumn(FormatField(dbf.GetField(i)));
while(dbf.Fetch()) {
Vector<Value> v;
v.Add(dbf.GetPos());
for(int i = 0; i < min(4, dbf.GetFieldCount()); i++)
v.Add(dbf[i]);
table.Add(v);
}
Run();
}
DbfView::DbfView()
{
s.Set(table, row);
s.SetPos(7000);
Add(s.SizePos());
Sizeable().Zoomable();
table.WhenEnterRow = THISBACK(EnterRow);
row.AddColumn("Column");
row.AddColumn("Value", 2);
}
GUI_APP_MAIN
{
SetDefaultCharset(CHARSET_WIN1252);
Ctrl::NoLayoutZoom();
DbfView().Perform();
}
I am moving this to the "library" area...
Mirek
|
|
|
Goto Forum:
Current Time: Fri Apr 19 13:35:56 CEST 2024
Total time taken to generate the page: 0.02151 seconds
|