memo.lines.add的问题(problems with memo.lines.add)
我正在尝试制作一个聊天应用程序,将消息发布到以下形式的备忘录中:
USERNAME-> Message
但它是这样贴在我的备忘录上的:
USERNAME
这是我的代码:
const cnMaxUserNameLen = 254; var sUserName: string; dwUserNameLen: DWORD; text : string; begin dwUserNameLen := cnMaxUserNameLen - 1; SetLength(sUserName, cnMaxUserNameLen); GetUserName(PChar(sUserName), dwUserNameLen); SetLength(sUserName, dwUserNameLen); text:= sUserName + '-> ' + edit1.Text; memo1.Lines.Add(text);
有关如何解决它的任何建议?
I am trying to make a chat application that will post a message into a memo in the form like this:
USERNAME-> Message
but it is posting to my memo like this:
USERNAME
Here is my code:
const cnMaxUserNameLen = 254; var sUserName: string; dwUserNameLen: DWORD; text : string; begin dwUserNameLen := cnMaxUserNameLen - 1; SetLength(sUserName, cnMaxUserNameLen); GetUserName(PChar(sUserName), dwUserNameLen); SetLength(sUserName, dwUserNameLen); text:= sUserName + '-> ' + edit1.Text; memo1.Lines.Add(text);
Any suggestions on how to fix it?
原文:https://stackoverflow.com/questions/8218628
更新时间:2022-02-21 15:02
最满意答案
好; 更复杂的答案:
public static IEnumerable<T> Intersect<T>(params IEnumerable<T>[] enums) { return Intersect<T>(null, enums); } public static IEnumerable<T> Intersect<T>(IComparer<T> comparer, params IEnumerable<T>[] enums) { if(enums == null) throw new ArgumentNullException("enums"); if(enums.Length == 0) return Enumerable.Empty<T>(); if(enums.Length == 1) return enums[0]; if(comparer == null) comparer = Comparer<T>.Default; return IntersectImpl(comparer, enums); } public static IEnumerable<T> IntersectImpl<T>(IComparer<T> comparer, IEnumerable<T>[] enums) { IEnumerator<T>[] iters = new IEnumerator<T>[enums.Length]; try { // create iterators and move as far as the first item for (int i = 0; i < enums.Length; i++) { if(!(iters[i] = enums[i].GetEnumerator()).MoveNext()) { yield break; // no data for one of the iterators } } bool first = true; T lastValue = default(T); do { // get the next item from the first sequence T value = iters[0].Current; if (!first && comparer.Compare(value, lastValue) == 0) continue; // dup in first source bool allTrue = true; for (int i = 1; i < iters.Length; i++) { var iter = iters[i]; // if any sequence isn't there yet, progress it; if any sequence // ends, we're all done while (comparer.Compare(iter.Current, value) < 0) { if (!iter.MoveNext()) goto alldone; // nasty, but } // if any sequence is now **past** value, then short-circuit if (comparer.Compare(iter.Current, value) > 0) { allTrue = false; break; } } // so all sequences have this value if (allTrue) yield return value; first = false; lastValue = value; } while (iters[0].MoveNext()); alldone: ; } finally { // clean up all iterators for (int i = 0; i < iters.Length; i++) { if (iters[i] != null) { try { iters[i].Dispose(); } catch { } } } } }
OK; more complex answer:
public static IEnumerable<T> Intersect<T>(params IEnumerable<T>[] enums) { return Intersect<T>(null, enums); } public static IEnumerable<T> Intersect<T>(IComparer<T> comparer, params IEnumerable<T>[] enums) { if(enums == null) throw new ArgumentNullException("enums"); if(enums.Length == 0) return Enumerable.Empty<T>(); if(enums.Length == 1) return enums[0]; if(comparer == null) comparer = Comparer<T>.Default; return IntersectImpl(comparer, enums); } public static IEnumerable<T> IntersectImpl<T>(IComparer<T> comparer, IEnumerable<T>[] enums) { IEnumerator<T>[] iters = new IEnumerator<T>[enums.Length]; try { // create iterators and move as far as the first item for (int i = 0; i < enums.Length; i++) { if(!(iters[i] = enums[i].GetEnumerator()).MoveNext()) { yield break; // no data for one of the iterators } } bool first = true; T lastValue = default(T); do { // get the next item from the first sequence T value = iters[0].Current; if (!first && comparer.Compare(value, lastValue) == 0) continue; // dup in first source bool allTrue = true; for (int i = 1; i < iters.Length; i++) { var iter = iters[i]; // if any sequence isn't there yet, progress it; if any sequence // ends, we're all done while (comparer.Compare(iter.Current, value) < 0) { if (!iter.MoveNext()) goto alldone; // nasty, but } // if any sequence is now **past** value, then short-circuit if (comparer.Compare(iter.Current, value) > 0) { allTrue = false; break; } } // so all sequences have this value if (allTrue) yield return value; first = false; lastValue = value; } while (iters[0].MoveNext()); alldone: ; } finally { // clean up all iterators for (int i = 0; i < iters.Length; i++) { if (iters[i] != null) { try { iters[i].Dispose(); } catch { } } } } }
相关问答
更多-
可枚举的先决条件(Preconditions for Enumerables)[2021-10-12]
以下是我可以按照个人喜好的降序排列的选项。 使用静态检查而不是运行时检查。 这样就不必枚举列表来进行检查。 该选项具有极其昂贵的限制。 我自己也无法访问静态检查程序,就像我希望的那样。 所以,你可以...... 在未来日期的预留中更改方法的定义以使其正常工作,以便不需要检查。 喜欢这个: void ProcessSchedules(IEnumerableschedules) { Contract.Requires (schedul ... -
N路合并算法(Algorithm for N-way merge)[2023-09-11]
以下想法如何: 创建优先级队列 通过每个文件迭代f 排队对(nextNumberIn(f),f)使用第一个值作为优先级键 而队列不为空 排队头(m,f) 输出m 如果f没有耗尽 入队(nextNumberIn(f),f) 由于可以在对数时间内对优先级队列添加元素,所以项2是O(N×log N) 。 由于while循环的(几乎全部)迭代添加了一个元素,整个while循环是O(M×log N) ,其中M是要排序的数字的总数。 假设所有文件都有非空序列,我们有M> N ,因此整个算法应该是O(M×log N) 。 ... -
players.transpose.map {|a| a.join(" ")} players.transpose.map {|a| a.join(" ")}
-
由于intersect1d每次排序数组,因此效率很低。 在这里,您必须将交叉点和每个样本扫描在一起以构建新的交叉点,这可以在线性时间内完成,从而保持顺序。 这种任务通常必须通过低级别例程手动调整。 这里有一种方法可以用numba做到这一点: from numba import njit import numpy as np @njit def drop_missing(intersect,sample): i=j=k=0 new_intersect=np.empty_like(inters ...
-
好; 更复杂的答案: public static IEnumerable
Intersect (params IEnumerable [] enums) { return Intersect (null, enums); } public static IEnumerable Intersect (IComparer comparer, params IEnumerable [] enums) { if(enums == null) throw new ... -
如果您创建一个序列相等比较器,如下所示: class SequenceEqualityComparer
: IEqualityComparer > { public bool Equals(IEnumerable a, IEnumerable b) { if (a == null) return b == null; if (b == null) return false; return a.Sequenc ... -
显然,你的模型的设置方式( Menu has_many categories , Category has_many dishes ),如果你要在同一个视图中显示所有这些信息,你没有别的办法,而只是循环遍历它们并显示所需的数据你的观点很好,恕我直言。 我没有看到任何问题。 只需一个提示,在循环关联模型的数据时,您只需要注意始终为关联的模型属性提供数据,否则您可能会获得undefined method 'method_name' for nil:NilClass一些的undefined method 'met ...
-
n平面交叉口(n planes intersection)[2022-06-04]
2个平面的交点是一条线。 3个平面的交点是3D空间中的一个点。 因此,在所有平面中,选择任意3个平面并找到它们的交点。 所有其他平面(如果它们确实在同一点交叉)也将在此点相交。 这就是你要找的地方! The intersection of 2 planes is a line. The intersection of 3 planes is a point in the 3D space. So, of all the planes, select any 3 planes and find their p ... -
根据不同函数排序的std :: vectors的交集(Intersection of std::vectors sorted according to different functions)[2022-03-06]
只需使用std::set_intersection()几次。 我认为你需要两个临时矢量来交替使用来存储结果。 如果你想只使用每个向量的一次传递,你只需使用它的通用版本,可能保留当前最小值的优先级队列。 Just use std::set_intersection() a couple of time. I think you'd need two temporary vectors used alternatingly to store the results. If you want to do it w ... -
第一个挑战是使功能正确。 一旦它是正确的,我们可以担心速度。 有一些东西可以绊倒像这样的函数: 为NaN 糟糕的限制 重复的数字 只有1个输入数组(或者根本没有) 您的原始函数可以处理重复的数字,例如[[9,9,9,9],[9,9,9]],但如果任何值是NaN,则会陷入无限循环,并处理0的限制为如果没有任何限制。 这是我的(Mk3)尝试: function intersection( arrs, limit ) { var result = [], posns = []; var j, v, ...