Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » ArrayCtrl.Clear() but? (Clear not erasing table contents)
ArrayCtrl.Clear() but? [message #57881] Sun, 26 December 2021 19:52 Go to next message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
Merry Christmas Smile

I have a simple program:
main.cpp:
#include "ClearTest.h"

arrayTest::arrayTest()
{
	CtrlLayout(*this, "Window title");
	ztest temp;
	cancel << [=] { Close(); };
	
	arrTest.AddColumn("Int");
	arrTest.AddColumn("Int");
	arrTest.AddColumn("Bool");

}

void arrayTest::LoadArray( Array<ztest> t)
{
	arrTest.Clear();
	for (int i = 0; i < t.GetCount(); i++) if (t[i].b) arrTest.Add(t[i].t[0], t[i].t[1], (int)t[i].b);
}

clearTest::clearTest() // using upp 15947 compiled on Linux Mint 20.2
{
	CtrlLayout(*this, "Window title");
	cancel << [=] { Close(); };
	btnRun << [=] {
	for (int i = 0; i < 10; i++) {
		ztest *temp = new ztest;
		srand (time(NULL));
		temp->t[0] = i + 1;
		temp->t[1] = i + (rand() % 100);
		temp->b = true;
		t.Add(pick(temp));
	}
		if (!aTest.IsOpen())
			aTest.LoadArray(clone(t));
			aTest.Open(this);
	};
}

GUI_APP_MAIN
{
	clearTest().Run();
}

ClearTest.h:
#ifndef _ClearTest_ClearTest_h
#define _ClearTest_ClearTest_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <ClearTest/ClearTest.lay>
#include <CtrlCore/lay.h>

struct ztest {
	int t[2];
	bool b;
};
static Array<ztest> t;

class arrayTest : public WithMyArray<TopWindow> {
public:
	void	LoadArray(Array<ztest> t);
			arrayTest();
};
class clearTest : public WithclearTestLayout<TopWindow> {
	arrayTest	aTest;
public:
	clearTest();
};

#endif

ClearTest.Lay
LAYOUT(clearTestLayout, 240, 148)
	ITEM(Upp::Button, btnRun, SetLabel(t_("RunbtnRun")).LeftPosZ(28, 56).TopPosZ(76, 15))
	ITEM(Upp::Button, cancel, SetLabel(t_("Close")).LeftPosZ(148, 56).TopPosZ(76, 15))
END_LAYOUT

LAYOUT(MyArray, 400, 200)
	ITEM(Upp::ArrayCtrl, arrTest, LeftPosZ(12, 380).TopPosZ(8, 140))
	ITEM(Upp::Button, cancel, SetLabel(t_("Close")).LeftPosZ(172, 56).TopPosZ(168, 15))
END_LAYOUT



It compiles and runs ok - but when I click on "RunbtnRun" repeatedly, instead of the array 'Clear()'ing, it adds to bottom of list growing each time.

Am I doing something wrong here?
Re: ArrayCtrl.Clear() but? [message #57882 is a reply to message #57881] Sun, 26 December 2021 19:55 Go to previous message
jimlef is currently offline  jimlef
Messages: 90
Registered: September 2020
Location: US
Member
In answer to my own issue, if I use pick() instead of clone(), it clears the array LOL go figure Smile
Previous Topic: Auto adjust row height in GridCtrl?
Next Topic: Adding void ArrayCtrl::SetLineTextColor(int i, Color c);
Goto Forum:
  


Current Time: Thu Mar 28 17:06:01 CET 2024

Total time taken to generate the page: 0.02469 seconds